-
Notifications
You must be signed in to change notification settings - Fork 3
/
FileIOAndMLStateTests.hs
40 lines (35 loc) · 1.05 KB
/
FileIOAndMLStateTests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE DataKinds #-}
{-|
Module : FileIOAndMLStateTests
Description : Example use cases of the combination of file IO and ML-style state from `Control.Runner.FileIOAndMLState`
Copyright : (c) Danel Ahman, 2019
License : MIT
Maintainer : [email protected]
Stability : experimental
This module provides some example use cases of the combination of
file IO and ML-style state from `Control.Runner.FileIOAndMLState`.
-}
module FileIOAndMLStateTests where
import Control.Runner
import Control.Runner.FileIO hiding (withFile)
import Control.Runner.FileIOAndMLState
import Control.Runner.MLState hiding (mlTopLevel)
test1 :: FilePath -> User '[IO,MLState] String
test1 fn =
do r <- alloc "";
withFile
fn
(
do s <- fRead;
r =:= s;
fWrite s -- to retain the file's original contents
);
s <- (!) r;
withFile
fn
(
fWrite (s ++ "foobar") -- updating the file's contents
);
s' <- (!) r;
return s'
test2 = ioMltopLevel (test1 "./out.txt")