on 88005d8 help sign in
43 lines 1.2 kB history raw
1module Effect.System
3-- Various system interaction features (this is not necessarily the right way
4-- to split them up, I just need some of them now :))
6import Effects
7import System
8import Control.IOExcept
10data System : Effect where
11 Args : sig System (List String)
12 Time : sig System Integer
13 GetEnv : String -> sig System (Maybe String)
14 CSystem : String -> sig System Int
16instance Handler System IO where
17 handle () Args k = do x <- getArgs; k x ()
18 handle () Time k = do x <- time; k x ()
19 handle () (GetEnv s) k = do x <- getEnv s; k x ()
20 handle () (CSystem s) k = do x <- system s; k x ()
22instance Handler System (IOExcept a) where
23 handle () Args k = do x <- ioe_lift getArgs; k x ()
24 handle () Time k = do x <- ioe_lift time; k x ()
25 handle () (GetEnv s) k = do x <- ioe_lift $ getEnv s; k x ()
26 handle () (CSystem s) k = do x <- ioe_lift $ system s; k x ()
28--- The Effect and associated functions
30SYSTEM : EFFECT
31SYSTEM = MkEff () System
33getArgs : Eff (List String) [SYSTEM]
34getArgs = call Args
36time : Eff Integer [SYSTEM]
37time = call Time
39getEnv : String -> Eff (Maybe String) [SYSTEM]
40getEnv s = call $ GetEnv s
42system : String -> Eff Int [SYSTEM]
43system s = call $ CSystem s