on master help sign in
Add beginnings of System effect
d9b6399Edwin Brady
libs/neweffects/Effect/System.idrnew file+38
@@ -0,0 +1,38 @@
1+module Effect.System
2+
3+-- Various system interaction features (this is not necessarily the right way
4+-- to split them up, I just need some of them now :))
5+
6+import Effects
7+import System
8+import Control.IOExcept
9+
10+data System : Effect where
11+ Args : { () } System (List String)
12+ Time : { () } System Int
13+ GetEnv : String -> { () } System (Maybe String)
14+
15+instance Handler System IO where
16+ handle () Args k = do x <- getArgs; k x ()
17+ handle () Time k = do x <- time; k x ()
18+ handle () (GetEnv s) k = do x <- getEnv s; k x ()
19+
20+instance Handler System (IOExcept a) where
21+ handle () Args k = do x <- ioe_lift getArgs; k x ()
22+ handle () Time k = do x <- ioe_lift time; k x ()
23+ handle () (GetEnv s) k = do x <- ioe_lift $ getEnv s; k x ()
24+
25+--- The Effect and associated functions
26+
27+SYSTEM : EFFECT
28+SYSTEM = MkEff () System
29+
30+getArgs : Handler System e => { [SYSTEM] } Eff e (List String)
31+getArgs = Args
32+
33+time : Handler System e => { [SYSTEM] } Eff e Int
34+time = Time
35+
36+getEnv : Handler System e => String -> { [SYSTEM] } Eff e (Maybe String)
37+getEnv s = GetEnv s
38+
libs/neweffects/neweffects.ipkg+1−1
@@ -5,5 +5,5 @@ modules = Effects, Effect.Default,
5
5
6 Effect.Exception, Effect.File, Effect.State,
6 Effect.Exception, Effect.File, Effect.State,
7 Effect.Random, Effect.StdIO, Effect.Select,
7 Effect.Random, Effect.StdIO, Effect.Select,
8− Effect.Memory
8+ Effect.Memory, Effect.System
9
9