on master help sign in
Trying a new Effects api

Changes: - Eff has become EffM, parameterised over (m : Type -> Type), which will allow us to introduce new effects later, though not currently used - Eff itself is now a collection of type synonyms which build an EffM. It can take either one list of effects, a list of input and output effects, or a list of effects and a function to compute output effects; disambiguated by context - EffT is as Eff, but takes the underlying 'm' - Added 'sig' function for giving effect signatures. All of the above mean we no longer need the {} syntactic sugar, though it's still there. Old effect programs (should!) work with no or minimal changes.

commitc3cdb9c46528f8e91a00fdab69e1a000d099327d authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 5 Apr 2015, 17:42 (12 years ago) parent5536314
12 files changed+180−150
libs/effects/Effect/Exception.idr+4−15 libs/effects/Effect/File.idr+16−16 libs/effects/Effect/Random.idr+12−13 libs/effects/Effect/Select.idr+2−2 libs/effects/Effect/State.idr+8−8 libs/effects/Effect/StdIO.idr+13−24 libs/effects/Effect/System.idr+8−8 libs/effects/Effects.idr+85−33 test/effects001/test021.idr+1−2 test/effects001/test021a.idr+1−1 test/effects002/test025.idr+2−2 test/effects003/hangman.idr+28−26
libs/effects/Effect/Exception.idr+4−15
@@ -4,8 +4,8 @@ import Effects
44import System
55import Control.IOExcept
66
7−data Exception : Type -> Effect where
8− Raise : a -> { () } Exception a b
7+data Exception : Type -> Effect where
8+ Raise : a -> sig (Exception a) b
99
1010instance Handler (Exception a) Maybe where
1111 handle _ (Raise e) k = Nothing
@@ -14,7 +14,7 @@ instance Handler (Exception a) List where
1414 handle _ (Raise e) k = []
1515
1616instance Show a => Handler (Exception a) IO where
17− handle _ (Raise e) k = do printLn e
17+ handle _ (Raise e) k = do print e
1818 believe_me (exit 1)
1919
2020instance Handler (Exception a) (IOExcept a) where
@@ -26,16 +26,5 @@ instance Handler (Exception a) (Either a) where
2626EXCEPTION : Type -> EFFECT
2727EXCEPTION t = MkEff () (Exception t)
2828
29−raise : a -> { [EXCEPTION a ] } Eff b
29+raise : a -> Eff b [EXCEPTION a]
3030raise err = call $ Raise err
31−
32−
33−
34−
35−
36−
37−-- TODO: Catching exceptions mid program?
38−-- probably need to invoke a new interpreter
39−
40−-- possibly add a 'handle' to the Eff language so that an alternative
41−-- handler can be introduced mid interpretation?
libs/effects/Effect/File.idr+16−16
@@ -46,29 +46,29 @@ data FileIO : Effect where
4646 ||| @ m The file mode.
4747 Open : (fname: String)
4848 -> (m : Mode)
49− -> {() ==> {res} if res
50− then OpenFile m
51− else ()} FileIO Bool
49+ -> sig FileIO Bool () (\res => case res of
50+ True => OpenFile m
51+ False => ())
5252
5353 ||| Close a file.
5454 |||
5555 ||| Closing a file moves the state from Open to closed.
56− Close : {OpenFile m ==> ()} FileIO ()
56+ Close : sig FileIO () (OpenFile m) ()
5757
5858 ||| Read a line from the file.
5959 |||
6060 ||| Only files that are open for reading can be read.
61− ReadLine : {OpenFile Read} FileIO String
61+ ReadLine : sig FileIO String (OpenFile Read)
6262
6363 ||| Write a string to a file.
6464 |||
6565 ||| Only file that are open for writing can be written to.
66− WriteString : String -> {OpenFile Write} FileIO ()
66+ WriteString : String -> sig FileIO () (OpenFile Write)
6767
6868 ||| End of file?
6969 |||
7070 ||| Only files open for reading can be tested for EOF
71− EOF : {OpenFile Read} FileIO Bool
71+ EOF : sig FileIO Bool (OpenFile Read)
7272
7373-- ------------------------------------------------------------ [ The Handlers ]
7474
@@ -117,31 +117,31 @@ FILE_IO t = MkEff t FileIO
117117||| @ m The file mode.
118118open : (fname : String)
119119 -> (m : Mode)
120− -> { [FILE_IO ()] ==> {result}
121− [FILE_IO (if result
122− then OpenFile m
123− else ())] } Eff Bool
120+ -> Eff Bool [FILE_IO ()]
121+ (\res => [FILE_IO (case res of
122+ True => OpenFile m
123+ False => ())])
124124open f m = call $ Open f m
125125
126126
127127||| Close a file.
128−close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff ()
128+close : Eff () [FILE_IO (OpenFile m)] [FILE_IO ()]
129129close = call $ Close
130130
131131||| Read a line from the file.
132−readLine : { [FILE_IO (OpenFile Read)] } Eff String
132+readLine : Eff String [FILE_IO (OpenFile Read)]
133133readLine = call $ ReadLine
134134
135135||| Write a string to a file.
136−writeString : String -> { [FILE_IO (OpenFile Write)] } Eff ()
136+writeString : String -> Eff () [FILE_IO (OpenFile Write)]
137137writeString str = call $ WriteString str
138138
139139||| Write a line to a file.
140−writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff ()
140+writeLine : String -> Eff () [FILE_IO (OpenFile Write)]
141141writeLine str = call $ WriteString (str ++ "\n")
142142
143143||| End of file?
144−eof : { [FILE_IO (OpenFile Read)] } Eff Bool
144+eof : Eff Bool [FILE_IO (OpenFile Read)]
145145eof = call $ EOF
146146
147147-- --------------------------------------------------------------------- [ EOF ]
libs/effects/Effect/Random.idr+12−13
@@ -5,28 +5,27 @@ import Data.Vect
55import Data.Fin
66
77data Random : Effect where
8− getRandom : { Integer } Random Integer
9− setSeed : Integer -> { Integer } Random ()
8+ getRandom : sig Random Integer Integer
9+ setSeed : Integer -> sig Random () Integer
1010
11−using (m : Type -> Type)
12− instance Handler Random m where
13− handle seed getRandom k
14− = let seed' = assert_total ((1664525 * seed + 1013904223) `prim__sremBigInt` (pow 2 32)) in
15− k seed' seed'
16− handle seed (setSeed n) k = k () n
11+instance Handler Random m where
12+ handle seed getRandom k
13+ = let seed' = assert_total ((1664525 * seed + 1013904223) `prim__sremBigInt` (pow 2 32)) in
14+ k seed' seed'
15+ handle seed (setSeed n) k = k () n
1716
1817RND : EFFECT
1918RND = MkEff Integer Random
2019
2120||| Generates a random Integer in a given range
22−rndInt : Integer -> Integer -> { [RND] } Eff Integer
21+rndInt : Integer -> Integer -> Eff Integer [RND]
2322rndInt lower upper = do v <- call $ getRandom
2423 return ((v `prim__sremBigInt` (upper - lower)) + lower)
2524
2625||| Generate a random number in Fin (S `k`)
2726|||
2827||| Note that rndFin k takes values 0, 1, ..., k.
29−rndFin : (k : Nat) -> { [RND] } Eff (Fin (S k))
28+rndFin : (k : Nat) -> Eff (Fin (S k)) [RND]
3029rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
3130 return (toFin v)
3231 where toFin : Integer -> Fin (S k)
@@ -35,15 +34,15 @@ rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast
3534 Nothing => toFin (assert_smaller x (x - cast (S k)))
3635
3736||| Select a random element from a vector
38−rndSelect' : Vect (S k) a -> { [RND] } Eff a
37+rndSelect' : Vect (S k) a -> Eff a [RND]
3938rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
4039
4140||| Select a random element from a list, or Nothing if the list is empty
42−rndSelect : List a -> { [RND] } Eff (Maybe a)
41+rndSelect : List a -> Eff (Maybe a) [RND]
4342rndSelect [] = return Nothing
4443rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
4544
4645||| Sets the random seed
47−srand : Integer -> { [RND] } Eff ()
46+srand : Integer -> Eff () [RND]
4847srand n = call $ setSeed n
4948
libs/effects/Effect/Select.idr+2−2
@@ -3,7 +3,7 @@ module Effect.Select
33import Effects
44
55data Selection : Effect where
6− Select : List a -> { () } Selection a
6+ Select : List a -> sig Selection a ()
77
88instance Handler Selection Maybe where
99 handle _ (Select xs) k = tryAll xs where
@@ -18,6 +18,6 @@ instance Handler Selection List where
1818SELECT : EFFECT
1919SELECT = MkEff () Selection
2020
21−select : List a -> { [SELECT] } Eff a
21+select : List a -> Eff a [SELECT]
2222select xs = call $ Select xs
2323
libs/effects/Effect/State.idr+8−8
@@ -5,8 +5,8 @@ import Effects
55%access public
66
77data State : Effect where
8− Get : { a } State a
9− Put : b -> { a ==> b } State ()
8+ Get : sig State a a
9+ Put : b -> sig State () a b
1010
1111-- using (m : Type -> Type)
1212instance Handler State m where
@@ -16,22 +16,22 @@ instance Handler State m where
1616STATE : Type -> EFFECT
1717STATE t = MkEff t State
1818
19−get : { [STATE x] } Eff x
19+get : Eff x [STATE x]
2020get = call $ Get
2121
22−put : x -> { [STATE x] } Eff ()
22+put : x -> Eff () [STATE x]
2323put val = call $ Put val
2424
25−putM : y -> { [STATE x] ==> [STATE y] } Eff ()
25+putM : y -> Eff () [STATE x] [STATE y]
2626putM val = call $ Put val
2727
28−update : (x -> x) -> { [STATE x] } Eff ()
28+update : (x -> x) -> Eff () [STATE x]
2929update f = put (f !get)
3030
31−updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff ()
31+updateM : (x -> y) -> Eff () [STATE x] [STATE y]
3232updateM f = putM (f !get)
3333
34−locally : x -> ({ [STATE x] } Eff t) -> { [STATE y] } Eff t
34+locally : x -> (Eff t [STATE x]) -> Eff t [STATE y]
3535locally newst prog = do st <- get
3636 putM newst
3737 val <- prog
libs/effects/Effect/StdIO.idr+13−24
@@ -9,10 +9,10 @@ import Control.IOExcept
99
1010||| The internal representation of StdIO effects
1111data StdIO : Effect where
12− PutStr : String -> { () } StdIO ()
13− GetStr : { () } StdIO String
14− PutCh : Char -> { () } StdIO ()
15− GetCh : { () } StdIO Char
12+ PutStr : String -> sig StdIO ()
13+ GetStr : sig StdIO String
14+ PutCh : Char -> sig StdIO ()
15+ GetCh : sig StdIO Char
1616
1717
1818-------------------------------------------------------------
@@ -22,13 +22,13 @@ data StdIO : Effect where
2222instance Handler StdIO IO where
2323 handle () (PutStr s) k = do putStr s; k () ()
2424 handle () GetStr k = do x <- getLine; k x ()
25− handle () (PutCh c) k = do putChar c; k () ()
25+ handle () (PutCh c) k = do putChar c; k () ()
2626 handle () GetCh k = do x <- getChar; k x ()
2727
2828instance Handler StdIO (IOExcept a) where
2929 handle () (PutStr s) k = do ioe_lift $ putStr s; k () ()
3030 handle () GetStr k = do x <- ioe_lift $ getLine; k x ()
31− handle () (PutCh c) k = do ioe_lift $ putChar c; k () ()
31+ handle () (PutCh c) k = do ioe_lift $ putChar c; k () ()
3232 handle () GetCh k = do x <- ioe_lift $ getChar; k x ()
3333
3434-------------------------------------------------------------
@@ -39,33 +39,22 @@ STDIO : EFFECT
3939STDIO = MkEff () StdIO
4040
4141||| Write a string to standard output.
42−putStr : String -> { [STDIO] } Eff ()
42+putStr : String -> Eff () [STDIO]
4343putStr s = call $ PutStr s
4444
45−||| Write a string to standard output, terminating with a newline.
46−putStrLn : String -> { [STDIO] } Eff ()
47−putStrLn s = putStr (s ++ "\n")
48−
4945||| Write a character to standard output.
50−putChar : Char -> { [STDIO] } Eff ()
46+putChar : Char -> Eff () [STDIO]
5147putChar c = call $ PutCh c
5248
53−||| Write a character to standard output, terminating with a newline.
54−putCharLn : Char -> { [STDIO] } Eff ()
55−putCharLn c = putStrLn (singleton c)
49+||| Write a string to standard output, terminating with a newline.
50+putStrLn : String -> Eff () [STDIO]
51+putStrLn s = putStr (s ++ "\n")
5652
5753||| Read a string from standard input.
58−getStr : { [STDIO] } Eff String
54+getStr : Eff String [STDIO]
5955getStr = call $ GetStr
6056
6157||| Read a character from standard input.
62−getChar : { [STDIO] } Eff Char
58+getChar : Eff Char [STDIO]
6359getChar = call $ GetCh
6460
65−||| Given a parameter `a` 'show' `a` to standard output.
66−print : Show a => a -> { [STDIO] } Eff ()
67−print a = putStr (show a)
68−
69−||| Given a parameter `a` 'show' `a` to a standard output, terminating with a newline
70−printLn : Show a => a -> { [STDIO] } Eff ()
71−printLn a = putStrLn (show a)
libs/effects/Effect/System.idr+8−8
@@ -8,10 +8,10 @@ import System
88import Control.IOExcept
99
1010data System : Effect where
11− Args : { () } System (List String)
12− Time : { () } System Int
13− GetEnv : String -> { () } System (Maybe String)
14− CSystem : String -> { () } System Int
11+ Args : sig System (List String)
12+ Time : sig System Int
13+ GetEnv : String -> sig System (Maybe String)
14+ CSystem : String -> sig System Int
1515
1616instance Handler System IO where
1717 handle () Args k = do x <- getArgs; k x ()
@@ -30,14 +30,14 @@ instance Handler System (IOExcept a) where
3030SYSTEM : EFFECT
3131SYSTEM = MkEff () System
3232
33−getArgs : { [SYSTEM] } Eff (List String)
33+getArgs : Eff (List String) [SYSTEM]
3434getArgs = call Args
3535
36−time : { [SYSTEM] } Eff Int
36+time : Eff Int [SYSTEM]
3737time = call Time
3838
39−getEnv : String -> { [SYSTEM] } Eff (Maybe String)
39+getEnv : String -> Eff (Maybe String) [SYSTEM]
4040getEnv s = call $ GetEnv s
4141
42−system : String -> { [SYSTEM] } Eff Int
42+system : String -> Eff Int [SYSTEM]
4343system s = call $ CSystem s
libs/effects/Effects.idr+85−33
@@ -24,6 +24,27 @@ Effect = (x : Type) -> Type -> (x -> Type) -> Type
2424data EFFECT : Type where
2525 MkEff : Type -> Effect -> EFFECT
2626
27+-- 'sig' gives the signature for an effect. There are three versions
28+-- depending on whether there is no state change, a non-dependent change,
29+-- or a dependent change. These are easily disambiguated by type.
30+
31+namespace NoResourceEffect
32+ sig : Effect -> Type -> Type
33+ sig e r = e r () (\v => ())
34+
35+namespace NoUpdateEffect
36+ sig : Effect -> (ret : Type) -> (resource : Type) -> Type
37+ sig e r e_in = e r e_in (\v => e_in)
38+
39+namespace UpdateEffect
40+ sig : Effect -> (ret : Type) -> (res_in : Type) -> (res_out : Type) -> Type
41+ sig e r e_in e_out = e r e_in (\v => e_out)
42+
43+namespace DepUpdateEffect
44+ sig : Effect ->
45+ (ret : Type) -> (res_in : Type) -> (res_out : ret -> Type) -> Type
46+ sig e r e_in e_out = e r e_in e_out
47+
2748||| Handler classes describe how an effect `e` is translated to the
2849||| underlying computation context `m` for execution.
2950class Handler (e : Effect) (m : Type -> Type) where
@@ -60,6 +81,7 @@ data SubList : List a -> List a -> Type where
6081 Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
6182 Drop : SubList xs ys -> SubList xs (x :: ys)
6283
84+%hint
6385subListId : SubList xs xs
6486subListId {xs = Nil} = SubNil
6587subListId {xs = x :: xs} = Keep subListId
@@ -133,26 +155,56 @@ relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
133155||| @ x The return type of the result.
134156||| @ es The list of allowed side-effects.
135157||| @ ce Function to compute a new list of allowed side-effects.
136−data Eff : (x : Type)
137− -> (es : List EFFECT)
138− -> (ce : x -> List EFFECT) -> Type where
139− value : (val : a) -> Eff a (xs val) xs
140− ebind : Eff a xs xs' ->
141− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
158+data EffM : (m : Type -> Type) -> (x : Type)
159+ -> (es : List EFFECT)
160+ -> (ce : x -> List EFFECT) -> Type where
161+ value : (val : a) -> EffM m a (xs val) xs
162+ ebind : EffM m a xs xs' ->
163+ ((val : a) -> EffM m b (xs' val) xs'') -> EffM m b xs xs''
142164 callP : (prf : EffElem e a xs) ->
143165 (eff : e t a b) ->
144− Eff t xs (\v => updateResTy v xs prf eff)
166+ EffM m t xs (\v => updateResTy v xs prf eff)
145167
146168 liftP : (prf : SubList ys xs) ->
147− Eff t ys ys' -> Eff t xs (\v => updateWith (ys' v) xs prf)
169+ EffM m t ys ys' -> EffM m t xs (\v => updateWith (ys' v) xs prf)
148170
149171 (:-) : (l : ty) ->
150− Eff t [x] xs' -> -- [x] (\v => xs) ->
151− Eff t [l ::: x] (\v => map (l :::) (xs' v))
172+ EffM m t [x] xs' -> -- [x] (\v => xs) ->
173+ EffM m t [l ::: x] (\v => map (l :::) (xs' v))
174+
175+-- Some type synonyms, so we don't always have to write EffM in full
176+
177+namespace SimpleEff
178+ -- Simple effects, no updates
179+ Eff : (x : Type) -> (es : List EFFECT) -> Type
180+ Eff x es = {m : Type -> Type} -> EffM m x es (\v => es)
181+
182+ EffT : (m : Type -> Type) -> (x : Type) -> (es : List EFFECT) -> Type
183+ EffT m x es = EffM m x es (\v => es)
184+
185+namespace TransEff
186+ -- Dependent effects, updates not dependent on result
187+ Eff : (x : Type) -> (es : List EFFECT) -> (ce : List EFFECT) -> Type
188+ Eff x es ce = {m : Type -> Type} -> EffM m x es (\_ => ce)
189+
190+ EffT : (m : Type -> Type) ->
191+ (x : Type) -> (es : List EFFECT) -> (ce : List EFFECT) -> Type
192+ EffT m x es ce = EffM m x es (\_ => ce)
193+
194+namespace DepEff
195+ -- Dependent effects, updates dependent on result
196+ Eff : (x : Type) -> (es : List EFFECT)
197+ -> (ce : x -> List EFFECT) -> Type
198+ Eff x es ce = {m : Type -> Type} -> EffM m x es ce
199+
200+ EffT : (m : Type -> Type) -> (x : Type) -> (es : List EFFECT)
201+ -> (ce : x -> List EFFECT) -> Type
202+ EffT m x es ce = EffM m x es ce
203+
152204
153205%no_implicit
154−(>>=) : Eff a xs xs' ->
155− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
206+(>>=) : EffM m a xs xs' ->
207+ ((val : a) -> EffM m b (xs' val) xs'') -> EffM m b xs xs''
156208(>>=) = ebind
157209
158210-- namespace SimpleBind
@@ -161,29 +213,29 @@ data Eff : (x : Type)
161213-- (>>=) = ebind
162214
163215||| Run a subprogram which results in an effect state the same as the input.
164−staticEff : Eff a xs (\v => xs) -> Eff a xs (\v => xs)
216+staticEff : EffM m a xs (\v => xs) -> EffM m a xs (\v => xs)
165217staticEff = id
166218
167219||| Explicitly give the expected set of result effects for an effectful
168220||| operation.
169−toEff : .(xs' : List EFFECT) -> Eff a xs (\v => xs') -> Eff a xs (\v => xs')
221+toEff : .(xs' : List EFFECT) -> EffM m a xs (\v => xs') -> EffM m a xs (\v => xs')
170222toEff xs' = id
171223
172−return : a -> Eff a xs (\v => xs)
224+return : a -> EffM m a xs (\v => xs)
173225return x = value x
174226
175227-- ------------------------------------------------------ [ for idiom brackets ]
176228
177229infixl 2 <*>
178230
179−pure : a -> Eff a xs (\v => xs)
231+pure : a -> EffM m a xs (\v => xs)
180232pure = value
181233
182−pureM : (val : a) -> Eff a (xs val) xs
234+pureM : (val : a) -> EffM m a (xs val) xs
183235pureM = value
184236
185−(<*>) : Eff (a -> b) xs (\v => xs) ->
186− Eff a xs (\v => xs) -> Eff b xs (\v => xs)
237+(<*>) : EffM m (a -> b) xs (\v => xs) ->
238+ EffM m a xs (\v => xs) -> EffM m b xs (\v => xs)
187239(<*>) prog v = do fn <- prog
188240 arg <- v
189241 return (fn arg)
@@ -203,7 +255,7 @@ execEff {e} {a} {res} {resk} (val :: env) (There p) eff k
203255-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
204256-- updates can be propagated even through failing computations?
205257
206−eff : Env m xs -> Eff a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
258+eff : Env m xs -> EffM m a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
207259eff env (value x) k = k x env
208260eff env (prog `ebind` c) k
209261 = eff env prog (\p', env' => eff env' (c p') k)
@@ -235,14 +287,14 @@ call : {a, b: _} -> {e : Effect} ->
235287 (eff : e t a b) ->
236288 {default tactics { search 100; }
237289 prf : EffElem e a xs} ->
238− Eff t xs (\v => updateResTy v xs prf eff)
290+ EffM m t xs (\v => updateResTy v xs prf eff)
239291call e {prf} = callP prf e
240292
241293implicit
242−lift : Eff t ys ys' ->
294+lift : EffM m t ys ys' ->
243295 {default tactics { search 100; }
244296 prf : SubList ys xs} ->
245− Eff t xs (\v => updateWith (ys' v) xs prf)
297+ EffM m t xs (\v => updateWith (ys' v) xs prf)
246298lift e {prf} = liftP prf e
247299
248300
@@ -255,7 +307,7 @@ lift e {prf} = liftP prf e
255307|||
256308||| @prog The effectful program to run.
257309run : Applicative m => {default MkDefaultEnv env : Env m xs}
258− -> (prog : Eff a xs xs') -> m a
310+ -> (prog : EffM m a xs xs') -> m a
259311run {env} prog = eff env prog (\r, env => pure r)
260312
261313||| Run an effectful program in the identity context.
@@ -264,7 +316,7 @@ run {env} prog = eff env prog (\r, env => pure r)
264316||| The `env` argument is implicit and initialised automatically.
265317|||
266318||| @prog The effectful program to run.
267−runPure : {default MkDefaultEnv env : Env id xs} -> (prog : Eff a xs xs') -> a
319+runPure : {default MkDefaultEnv env : Env id xs} -> (prog : EffM id a xs xs') -> a
268320runPure {env} prog = eff env prog (\r, env => r)
269321
270322||| Run an effectful program in a given context `m` with a default value for the environment.
@@ -273,7 +325,7 @@ runPure {env} prog = eff env prog (\r, env => r)
273325|||
274326||| @env The environment to use.
275327||| @prog The effectful program to run.
276−runInit : Applicative m => (env : Env m xs) -> (prog : Eff a xs xs') -> m a
328+runInit : Applicative m => (env : Env m xs) -> (prog : EffM m a xs xs') -> m a
277329runInit env prog = eff env prog (\r, env => pure r)
278330
279331||| Run an effectful program with a given default value for the environment.
@@ -282,31 +334,31 @@ runInit env prog = eff env prog (\r, env => pure r)
282334|||
283335||| @env The environment to use.
284336||| @prog The effectful program to run.
285−runPureInit : (env : Env id xs) -> (prog : Eff a xs xs') -> a
337+runPureInit : (env : Env id xs) -> (prog : EffM id a xs xs') -> a
286338runPureInit env prog = eff env prog (\r, env => r)
287339
288−runWith : (a -> m a) -> Env m xs -> Eff a xs xs' -> m a
340+runWith : (a -> m a) -> Env m xs -> EffM m a xs xs' -> m a
289341runWith inj env prog = eff env prog (\r, env => inj r)
290342
291−runEnv : Applicative m => Env m xs -> Eff a xs xs' ->
343+runEnv : Applicative m => Env m xs -> EffM m a xs xs' ->
292344 m (x : a ** Env m (xs' x))
293345runEnv env prog = eff env prog (\r, env => pure (r ** env))
294346
295347-- ----------------------------------------------- [ some higher order things ]
296348
297−mapE : (a -> {xs} Eff b) -> List a -> {xs} Eff (List b)
349+mapE : (a -> {xs} EffM m b) -> List a -> {xs} EffM m (List b)
298350mapE f [] = pure []
299351mapE f (x :: xs) = [| f x :: mapE f xs |]
300352
301353
302−mapVE : (a -> {xs} Eff b) ->
354+mapVE : (a -> {xs} EffM m b) ->
303355 Vect n a ->
304− {xs} Eff (Vect n b)
356+ {xs} EffM m (Vect n b)
305357mapVE f [] = pure []
306358mapVE f (x :: xs) = [| f x :: mapVE f xs |]
307359
308360
309−when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
361+when : Bool -> Lazy ({xs} EffM m ()) -> {xs} EffM m ()
310362when True e = Force e
311363when False e = pure ()
312364
test/effects001/test021.idr+1−2
@@ -9,8 +9,7 @@ import Control.IOExcept
99data Count : Type where
1010
1111FileIO : Type -> Type -> Type
12−FileIO st t
13− = { [FILE_IO st, STDIO, Count ::: STATE Int] } Eff t
12+FileIO st t = Eff t [FILE_IO st, STDIO, Count ::: STATE Int]
1413
1514readFile : FileIO (OpenFile Read) (List String)
1615readFile = readAcc [] where
test/effects001/test021a.idr+1−1
@@ -18,7 +18,7 @@ Env = List (String, Integer)
1818-- Evaluator t
1919-- = Eff m [EXCEPTION String, RND, STATE Env] t
2020
21−eval : Expr -> { [EXCEPTION String, STDIO, RND, STATE Env] } Eff Integer
21+eval : Expr -> Eff Integer [EXCEPTION String, STDIO, RND, STATE Env]
2222eval (Var x) = do vs <- get
2323 case lookup x vs of
2424 Nothing => raise ("No such variable " ++ x)
test/effects002/test025.idr+2−2
@@ -6,8 +6,8 @@ import Control.IOExcept
66import Data.Vect
77
88MemoryIO : Type -> Type -> Type -> Type
9−MemoryIO td ts r = { [ Dst ::: RAW_MEMORY td
10− , Src ::: RAW_MEMORY ts ] } Eff r
9+MemoryIO td ts r = Eff r [Dst ::: RAW_MEMORY td,
10+ Src ::: RAW_MEMORY ts]
1111
1212inpVect : Vect 5 Bits8
1313inpVect = map prim__truncInt_B8 [0, 1, 2, 3, 5]
test/effects003/hangman.idr+28−26
@@ -74,55 +74,59 @@ data HangmanRules : Effect where
7474-- the number of missing letters, if not, reduce the number of guesses left
7575
7676 Guess : (x : Char) ->
77− { Hangman (Running (S g) (S w)) ==>
78− {inword} (case inword of
77+ sig HangmanRules Bool
78+ (Hangman (Running (S g) (S w)))
79+ (\inword =>
80+ case inword of
7981 True => Hangman (Running (S g) w)
80− False => Hangman (Running g (S w))) }
81− HangmanRules Bool
82+ False => Hangman (Running g (S w)))
8283
8384-- The 'Won' operation requires that there are no missing letters
8485
85− Won : { Hangman (Running g 0) ==> Hangman NotRunning } HangmanRules ()
86+ Won : sig HangmanRules ()
87+ (Hangman (Running g 0))
88+ (Hangman NotRunning)
8689
8790-- The 'Lost' operation requires that there are no guesses left
8891
89− Lost : { Hangman (Running 0 g) ==> Hangman NotRunning } HangmanRules ()
92+ Lost : sig HangmanRules ()
93+ (Hangman (Running 0 g))
94+ (Hangman NotRunning)
9095
9196-- Set up a new game, initialised with 6 guesses and the missing letters in
9297-- the given word. Note that if there are no letters in the word, we won't
9398-- be able to run 'Guess'!
9499
95100 NewWord : (w : String) ->
96− { h ==> Hangman (Running 6 (length (letters w))) } HangmanRules ()
101+ sig HangmanRules () h (Hangman (Running 6 (length (letters w))))
97102
98103-- Finally, allow us to get the current game state
99104
100− Get : { h } HangmanRules h
105+ Get : sig HangmanRules h h
101106
102107HANGMAN : HState -> EFFECT
103108HANGMAN h = MkEff (Hangman h) HangmanRules
104109
105110-- Promote explicit effecst to Eff programs
106111
107−guess : Char ->
108− { [HANGMAN (Running (S g) (S w))] ==>
109− {inword} [HANGMAN (case inword of
110− True => Running (S g) w
111− False => Running g (S w))] } Eff Bool
112+guess : Char -> Eff Bool
113+ [HANGMAN (Running (S g) (S w))]
114+ (\inword => [HANGMAN (case inword of
115+ True => Running (S g) w
116+ False => Running g (S w))])
112117guess c = call (Main.Guess c)
113118
114−won : { [HANGMAN (Running g 0)] ==> [HANGMAN NotRunning]} Eff ()
119+won : Eff () [HANGMAN (Running g 0)] [HANGMAN NotRunning]
115120won = call Won
116121
117−lost : { [HANGMAN (Running 0 g)] ==> [HANGMAN NotRunning]} Eff ()
122+lost : Eff () [HANGMAN (Running 0 g)] [HANGMAN NotRunning]
118123lost = call Lost
119124
120−new_word : (w : String) ->
121− { [HANGMAN h] ==>
122− [HANGMAN (Running 6 (length (letters w)))]} Eff ()
125+new_word : (w : String) -> Eff () [HANGMAN h]
126+ [HANGMAN (Running 6 (length (letters w)))]
123127new_word w = call (NewWord w)
124128
125−get : { [HANGMAN h] } Eff (Hangman h)
129+get : Eff (Hangman h) [HANGMAN h]
126130get = call Get
127131
128132-----------------------------------------------------------------------
@@ -163,8 +167,8 @@ were valid letters in it!
163167soRefl : So x -> (x = True)
164168soRefl Oh = Refl
165169
166−game : { [HANGMAN (Running (S g) w), STDIO] ==>
167− [HANGMAN NotRunning, STDIO] } Eff ()
170+game : Eff () [HANGMAN (Running (S g) w), STDIO]
171+ [HANGMAN NotRunning, STDIO]
168172game {w=Z} = won
169173game {w=S _}
170174 = do putStrLn (show !get)
@@ -175,10 +179,8 @@ game {w=S _}
175179 (Right p) => do putStrLn "Invalid input!"
176180 game
177181 where
178− processGuess : -- {g,w:_} ->
179− Char -> { [HANGMAN (Running (S g) (S w)), STDIO] ==>
180− [HANGMAN NotRunning, STDIO] }
181− Eff ()
182+ processGuess : Char -> Eff () [HANGMAN (Running (S g) (S w)), STDIO]
183+ [HANGMAN NotRunning, STDIO]
182184 processGuess {g} c {w}
183185 = case !(guess c) of
184186 True => do putStrLn "Good guess!"
@@ -203,7 +205,7 @@ wlen = proof search
203205
204206{- It typechecks! Ship it! -}
205207
206−runGame : { [HANGMAN NotRunning, RND, STDIO] } Eff ()
208+runGame : Eff () [HANGMAN NotRunning, RND, STDIO]
207209runGame = do srand 1234567890
208210 let w = index !(rndFin _) words
209211 new_word w