on 372d2ea help sign in
45 lines 1.3 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
10%access public export
12data System : Effect where
13 Args : sig System (List String)
14 Time : sig System Integer
15 GetEnv : String -> sig System (Maybe String)
16 CSystem : String -> sig System Int
18implementation Handler System IO where
19 handle () Args k = do x <- getArgs; k x ()
20 handle () Time k = do x <- time; k x ()
21 handle () (GetEnv s) k = do x <- getEnv s; k x ()
22 handle () (CSystem s) k = do x <- system s; k x ()
24implementation Handler System (IOExcept a) where
25 handle () Args k = do x <- ioe_lift getArgs; k x ()
26 handle () Time k = do x <- ioe_lift time; k x ()
27 handle () (GetEnv s) k = do x <- ioe_lift $ getEnv s; k x ()
28 handle () (CSystem s) k = do x <- ioe_lift $ system s; k x ()
30--- The Effect and associated functions
32SYSTEM : EFFECT
33SYSTEM = MkEff () System
35getArgs : Eff (List String) [SYSTEM]
36getArgs = call Args
38time : Eff Integer [SYSTEM]
39time = call Time
41getEnv : String -> Eff (Maybe String) [SYSTEM]
42getEnv s = call $ GetEnv s
44system : String -> Eff Int [SYSTEM]
45system s = call $ CSystem s