on master help sign in
Replace 'effects' with neweffects
commitced7733b7600325f62ec67adfdf7884b0427e10b authorEdwin Brady <ecb10@st-andrews.ac.uk> dateTue 15 Jul 2014, 21:35 (12 years ago) parent6e39ba5
29 files changed+267−272
CHANGELOG+1−1 libs/Makefile−5 libs/effects/Effect/Exception.idr+1−1 libs/effects/Effect/File.idr+5−5 libs/effects/Effect/Memory.idr+8−8 libs/effects/Effect/Random.idr+5−5 libs/effects/Effect/Select.idr+1−1 libs/effects/Effect/State.idr+8−8 libs/effects/Effect/StdIO.idr+5−5 libs/effects/Effect/System.idr+4−4 libs/effects/Effects.idr+59−102 libs/effects/Makefile+5−13 libs/neweffects/Makefile−14 libs/neweffects/Effect/Default.idr → libs/oldeffects/Effect/Default.idr libs/neweffects/Effect/Exception.idr → libs/oldeffects/Effect/Exception.idr+1−1 libs/neweffects/Effect/File.idr → libs/oldeffects/Effect/File.idr+5−5 libs/neweffects/Effect/Memory.idr → libs/oldeffects/Effect/Memory.idr+8−8 libs/neweffects/Effect/Monad.idr → libs/oldeffects/Effect/Monad.idr libs/neweffects/Effect/Random.idr → libs/oldeffects/Effect/Random.idr+5−5 libs/neweffects/Effect/Select.idr → libs/oldeffects/Effect/Select.idr+1−1 libs/neweffects/Effect/State.idr → libs/oldeffects/Effect/State.idr+8−8 libs/neweffects/Effect/StdIO.idr → libs/oldeffects/Effect/StdIO.idr+5−5 libs/neweffects/Effect/System.idr → libs/oldeffects/Effect/System.idr+4−4 libs/neweffects/Effects.idr → libs/oldeffects/Effects.idr+102−59 libs/oldeffects/Makefile+22 libs/neweffects/effects.ipkg → libs/oldeffects/effects.ipkg+1−1 test/effects001/test021.idr+1−1 test/effects001/test021a.idr+1−1 test/effects002/test025.idr+1−1
CHANGELOG+1−1
@@ -7,7 +7,7 @@ New in 0.9.14:
77* Clearly distinguish between type providers and postulate providers at the use site
88* Allow dependent function syntax to be overridden in dsl blocks, similarly to
99 functions and let. The keyword for this is "pi".
10−* Experimental 'neweffects' library, with simplified API
10+* Updated 'effects' library, with simplified API
1111* All new JavaScript backend (avoids callstack overflows)
1212* Add support for %lib directive for NodeJS
1313* Quasiquotes and quasiquote patterns allow easier work with reflected terms.
libs/Makefile−5
@@ -2,32 +2,27 @@ build:
22 $(MAKE) -C prelude build
33 $(MAKE) -C base build
44 $(MAKE) -C effects build
5− $(MAKE) -C neweffects build
65
76
87install:
98 $(MAKE) -C prelude install
109 $(MAKE) -C base install
1110 $(MAKE) -C effects install
12− $(MAKE) -C neweffects install
1311
1412clean:
1513 $(MAKE) -C prelude clean
1614 $(MAKE) -C base clean
1715 $(MAKE) -C effects clean
18− $(MAKE) -C neweffects clean
1916
2017doc:
2118 $(MAKE) -C prelude doc
2219 $(MAKE) -C base doc
2320 $(MAKE) -C effects doc
24− $(MAKE) -C neweffects doc
2521
2622doc_clean:
2723 $(MAKE) -C prelude doc_clean
2824 $(MAKE) -C base doc_clean
2925 $(MAKE) -C effects doc_clean
30− $(MAKE) -C neweffects doc_clean
3126
3227
3328.PHONY: build install clean doc doc_clean
libs/effects/Effect/Exception.idr+1−1
@@ -26,7 +26,7 @@ instance Handler (Exception a) (Either a) where
2626EXCEPTION : Type -> EFFECT
2727EXCEPTION t = MkEff () (Exception t)
2828
29−raise : a -> { [EXCEPTION a ] } Eff m b
29+raise : a -> { [EXCEPTION a ] } Eff b
3030raise err = call $ Raise err
3131
3232
libs/effects/Effect/File.idr+5−5
@@ -105,24 +105,24 @@ open : (fname : String)
105105 -> (m : Mode)
106106 -> { [FILE_IO ()] ==> [FILE_IO (if result
107107 then OpenFile m
108− else ())] } Eff e Bool
108+ else ())] } Eff Bool
109109open f m = call $ Open f m
110110
111111
112112||| Close a file.
113−close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff e ()
113+close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff ()
114114close = call $ Close
115115
116116||| Read a line from the file.
117−readLine : { [FILE_IO (OpenFile Read)] } Eff e String
117+readLine : { [FILE_IO (OpenFile Read)] } Eff String
118118readLine = call $ ReadLine
119119
120120||| Write a line to a file.
121−writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff e ()
121+writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff ()
122122writeLine str = call $ WriteLine str
123123
124124||| End of file?
125−eof : { [FILE_IO (OpenFile Read)] } Eff e Bool
125+eof : { [FILE_IO (OpenFile Read)] } Eff Bool
126126eof = call $ EOF
127127
128128-- --------------------------------------------------------------------- [ EOF ]
libs/effects/Effect/Memory.idr+8−8
@@ -101,7 +101,7 @@ RAW_MEMORY : Type -> EFFECT
101101RAW_MEMORY t = MkEff t RawMemory
102102
103103allocate : (n : Nat) ->
104− Eff m () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
104+ Eff () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
105105allocate size = call $ Allocate size
106106
107107initialize : {i : Nat} ->
@@ -109,18 +109,18 @@ initialize : {i : Nat} ->
109109 Bits8 ->
110110 (size : Nat) ->
111111 so (i + size <= n) ->
112− Eff m () [RAW_MEMORY (MemoryChunk n i)]
112+ Eff () [RAW_MEMORY (MemoryChunk n i)]
113113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
114114initialize c size prf = call $ Initialize c size prf
115115
116−free : Eff m () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
116+free : Eff () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
117117free = call Free
118118
119119peek : {i : Nat} ->
120120 (offset : Nat) ->
121121 (size : Nat) ->
122122 so (offset + size <= i) ->
123− { [RAW_MEMORY (MemoryChunk n i)] } Eff m (Vect size Bits8)
123+ { [RAW_MEMORY (MemoryChunk n i)] } Eff (Vect size Bits8)
124124peek offset size prf = call $ Peek offset size prf
125125
126126poke : {n : Nat} ->
@@ -128,12 +128,12 @@ poke : {n : Nat} ->
128128 (offset : Nat) ->
129129 Vect size Bits8 ->
130130 so (offset <= i && offset + size <= n) ->
131− Eff m () [RAW_MEMORY (MemoryChunk n i)]
131+ Eff () [RAW_MEMORY (MemoryChunk n i)]
132132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
133133poke offset content prf = call $ Poke offset content prf
134134
135135private
136−getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff m (MemoryChunk n i)
136+getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff (MemoryChunk n i)
137137getRawPtr = call $ GetRawPtr
138138
139139private
@@ -146,7 +146,7 @@ move' : {dst_size : Nat} ->
146146 (size : Nat) ->
147147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
148148 so (src_offset + size <= src_init) ->
149− Eff m () [RAW_MEMORY (MemoryChunk dst_size dst_init)]
149+ Eff () [RAW_MEMORY (MemoryChunk dst_size dst_init)]
150150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
151151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
152152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
@@ -162,7 +162,7 @@ move : {dst_size : Nat} ->
162162 (size : Nat) ->
163163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
164164 so (src_offset + size <= src_init) ->
165− Eff m ()
165+ Eff ()
166166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
167167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
168168 (\v =>
libs/effects/Effect/Random.idr+5−5
@@ -17,14 +17,14 @@ RND : EFFECT
1717RND = MkEff Integer Random
1818
1919||| Generates a random Integer in a given range
20−rndInt : Integer -> Integer -> { [RND] } Eff m Integer
20+rndInt : Integer -> Integer -> { [RND] } Eff Integer
2121rndInt lower upper = do v <- call $ getRandom
2222 return (v `prim__sremBigInt` (upper - lower) + lower)
2323
2424||| Generate a random number in Fin (S `k`)
2525|||
2626||| Note that rndFin k takes values 0, 1, ..., k.
27−rndFin : (k : Nat) -> { [RND] } Eff m (Fin (S k))
27+rndFin : (k : Nat) -> { [RND] } Eff (Fin (S k))
2828rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
2929 return (toFin v)
3030 where toFin : Integer -> Fin (S k)
@@ -33,15 +33,15 @@ rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast
3333 Nothing => toFin (assert_smaller x (x - cast (S k)))
3434
3535||| Select a random element from a vector
36−rndSelect' : Vect (S k) a -> { [RND] } Eff IO a
36+rndSelect' : Vect (S k) a -> { [RND] } Eff a
3737rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
3838
3939||| Select a random element from a list, or Nothing if the list is empty
40−rndSelect : List a -> { [RND] } Eff IO (Maybe a)
40+rndSelect : List a -> { [RND] } Eff (Maybe a)
4141rndSelect [] = return Nothing
4242rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
4343
4444||| Sets the random seed
45−srand : Integer -> { [RND] } Eff m ()
45+srand : Integer -> { [RND] } Eff ()
4646srand n = call $ setSeed n
4747
libs/effects/Effect/Select.idr+1−1
@@ -18,6 +18,6 @@ instance Handler Selection List where
1818SELECT : EFFECT
1919SELECT = MkEff () Selection
2020
21−select : List a -> { [SELECT] } Eff m a
21+select : List a -> { [SELECT] } Eff a
2222select xs = call $ Select xs
2323
libs/effects/Effect/State.idr+8−8
@@ -8,30 +8,30 @@ data State : Effect where
88 Get : { a } State a
99 Put : b -> { a ==> b } State ()
1010
11−using (m : Type -> Type)
12− instance Handler State m where
11+-- using (m : Type -> Type)
12+instance Handler State m where
1313 handle st Get k = k st st
1414 handle st (Put n) k = k () n
1515
1616STATE : Type -> EFFECT
1717STATE t = MkEff t State
1818
19−get : { [STATE x] } Eff m x
19+get : { [STATE x] } Eff x
2020get = call $ Get
2121
22−put : x -> { [STATE x] } Eff m ()
22+put : x -> { [STATE x] } Eff ()
2323put val = call $ Put val
2424
25−putM : y -> { [STATE x] ==> [STATE y] } Eff m ()
25+putM : y -> { [STATE x] ==> [STATE y] } Eff ()
2626putM val = call $ Put val
2727
28−update : (x -> x) -> { [STATE x] } Eff m ()
28+update : (x -> x) -> { [STATE x] } Eff ()
2929update f = put (f !get)
3030
31−updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff m ()
31+updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff ()
3232updateM f = putM (f !get)
3333
34−locally : x -> ({ [STATE x] } Eff m t) -> { [STATE y] } Eff m t
34+locally : x -> ({ [STATE x] } Eff t) -> { [STATE y] } Eff t
3535locally newst prog = do st <- get
3636 putM newst
3737 val <- prog
libs/effects/Effect/StdIO.idr+5−5
@@ -39,22 +39,22 @@ STDIO : EFFECT
3939STDIO = MkEff () StdIO
4040
4141||| Write a string to standard output.
42−putStr : String -> { [STDIO] } Eff e ()
42+putStr : String -> { [STDIO] } Eff ()
4343putStr s = call $ PutStr s
4444
4545||| Write a character to standard output.
46−putChar : Char -> { [STDIO] } Eff e ()
46+putChar : Char -> { [STDIO] } Eff ()
4747putChar c = call $ PutCh c
4848
4949||| Write a string to standard output, terminating with a newline.
50−putStrLn : String -> { [STDIO] } Eff e ()
50+putStrLn : String -> { [STDIO] } Eff ()
5151putStrLn s = putStr (s ++ "\n")
5252
5353||| Read a string from standard input.
54−getStr : { [STDIO] } Eff e String
54+getStr : { [STDIO] } Eff String
5555getStr = call $ GetStr
5656
5757||| Read a character from standard input.
58−getChar : { [STDIO] } Eff e Char
58+getChar : { [STDIO] } Eff Char
5959getChar = call $ GetCh
6060
libs/effects/Effect/System.idr+4−4
@@ -30,14 +30,14 @@ instance Handler System (IOExcept a) where
3030SYSTEM : EFFECT
3131SYSTEM = MkEff () System
3232
33−getArgs : Handler System e => { [SYSTEM] } Eff e (List String)
33+getArgs : { [SYSTEM] } Eff (List String)
3434getArgs = call Args
3535
36−time : Handler System e => { [SYSTEM] } Eff e Int
36+time : { [SYSTEM] } Eff Int
3737time = call Time
3838
39−getEnv : Handler System e => String -> { [SYSTEM] } Eff e (Maybe String)
39+getEnv : String -> { [SYSTEM] } Eff (Maybe String)
4040getEnv s = call $ GetEnv s
4141
42−system : Handler System e => String -> { [SYSTEM] } Eff e Int
42+system : String -> { [SYSTEM] } Eff Int
4343system s = call $ CSystem s
libs/effects/Effects.idr+59−102
@@ -10,7 +10,7 @@ import Effect.Default
1010%access public
1111-- ----------------------------------------------------------------- [ Effects ]
1212||| The Effect type describes effectful computations.
13−|||
13+|||
1414||| This type is parameterised by:
1515||| + The input resource.
1616||| + The return type of the computation.
@@ -28,11 +28,11 @@ data EFFECT : Type where
2828||| underlying computation context `m` for execution.
2929class Handler (e : Effect) (m : Type -> Type) where
3030 ||| How to handle the effect.
31− |||
31+ |||
3232 ||| @ r The resource being handled.
3333 ||| @ eff The effect to be applied.
3434 ||| @ k The continuation to pass the result of the effect
35− covering handle : (r : res) -> (eff : e t res resk) ->
35+ covering handle : (r : res) -> (eff : e t res resk) ->
3636 (k : ((x : t) -> resk x -> m a)) -> m a
3737
3838||| Get the resource type (handy at the REPL to find out about an effect)
@@ -48,28 +48,27 @@ resourceType (MkEff t e) = t
4848syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
4949
5050-- The state transition is dependent on a result `b`, a bound variable.
51−syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
51+syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
5252 = eff inst (\b => outst)
5353
5454--- A simple state transition
5555syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
5656
5757-- --------------------------------------- [ Properties and Proof Construction ]
58−using (xs : List a, ys : List a)
59− data SubList : List a -> List a -> Type where
60− SubNil : SubList {a} [] []
61− Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
62− Drop : SubList xs ys -> SubList xs (x :: ys)
58+data SubList : List a -> List a -> Type where
59+ SubNil : SubList [] []
60+ Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
61+ Drop : SubList xs ys -> SubList xs (x :: ys)
6362
64− subListId : SubList xs xs
65− subListId {xs = Nil} = SubNil
66− subListId {xs = x :: xs} = Keep subListId
63+subListId : SubList xs xs
64+subListId {xs = Nil} = SubNil
65+subListId {xs = x :: xs} = Keep subListId
6766
6867namespace Env
6968 data Env : (m : Type -> Type) -> List EFFECT -> Type where
7069 Nil : Env m Nil
7170 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
72−
71+
7372data EffElem : Effect -> Type ->
7473 List EFFECT -> Type where
7574 Here : EffElem x a (MkEff a x :: xs)
@@ -129,71 +128,62 @@ relabel {xs = []} l [] = []
129128relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
130129
131130-- ------------------------------------------------- [ The Language of Effects ]
132−||| Definition of an Effect.
133−|||
134−||| @ m The computation context
131+||| Definition of a language of effectful programs.
132+|||
135133||| @ x The return type of the result.
136134||| @ es The list of allowed side-effects.
137135||| @ ce Function to compute a new list of allowed side-effects.
138−data Eff : (m : Type -> Type)
139− -> (x : Type)
136+data Eff : (x : Type)
140137 -> (es : List EFFECT)
141138 -> (ce : x -> List EFFECT) -> Type where
142− value : a -> Eff m a xs (\v => xs)
143− with_val : (val : a) -> Eff m () xs (\v => xs' val) ->
144− Eff m a xs xs'
145− ebind : Eff m a xs xs' ->
146− ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
139+ value : a -> Eff a xs (\v => xs)
140+ with_val : (val : a) -> Eff () xs (\v => xs' val) ->
141+ Eff a xs xs'
142+ ebind : Eff a xs xs' ->
143+ ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
147144 callP : (prf : EffElem e a xs) ->
148145 (eff : e t a b) ->
149− Eff m t xs (\v => updateResTy v xs prf eff)
146+ Eff t xs (\v => updateResTy v xs prf eff)
150147
151148 liftP : (prf : SubList ys xs) ->
152− Eff m t ys ys' -> Eff m t xs (\v => updateWith (ys' v) xs prf)
153− newInit : Handler e m =>
154− res ->
155− Eff m a (MkEff res e :: xs) (\v => (MkEff res' e :: xs')) ->
156− Eff m a xs (\v => xs')
157− catch : Catchable m err =>
158− Eff m a xs xs' -> (err -> Eff m a xs xs') ->
159− Eff m a xs xs'
160−
161− (:-) : (l : ty) ->
162− Eff m t [x] xs' -> -- [x] (\v => xs) ->
163− Eff m t [l ::: x] (\v => map (l :::) (xs' v))
164−
165−(>>=) : Eff m a xs xs' ->
166− ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
167−(>>=) = ebind
149+ Eff t ys ys' -> Eff t xs (\v => updateWith (ys' v) xs prf)
150+
151+ (:-) : (l : ty) ->
152+ Eff t [x] xs' -> -- [x] (\v => xs) ->
153+ Eff t [l ::: x] (\v => map (l :::) (xs' v))
154+
155+(>>=) : Eff a xs xs' ->
156+ ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
157+(>>=) = ebind
168158
169159-- namespace SimpleBind
170−-- (>>=) : Eff m a xs (\v => xs) ->
160+-- (>>=) : Eff m a xs (\v => xs) ->
171161-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
172−-- (>>=) = ebind
162+-- (>>=) = ebind
173163
174164||| Run a subprogram which results in an effect state the same as the input.
175−staticEff : Eff m a xs (\v => xs) -> Eff m a xs (\v => xs)
165+staticEff : Eff a xs (\v => xs) -> Eff a xs (\v => xs)
176166staticEff = id
177167
178168||| Explicitly give the expected set of result effects for an effectful
179169||| operation.
180−toEff : .(xs' : List EFFECT) -> Eff m a xs (\v => xs') -> Eff m a xs (\v => xs')
170+toEff : .(xs' : List EFFECT) -> Eff a xs (\v => xs') -> Eff a xs (\v => xs')
181171toEff xs' = id
182172
183−return : a -> Eff m a xs (\v => xs)
173+return : a -> Eff a xs (\v => xs)
184174return x = value x
185175
186176-- ------------------------------------------------------ [ for idiom brackets ]
187177
188178infixl 2 <$>
189179
190−pure : a -> Eff m a xs (\v => xs)
180+pure : a -> Eff a xs (\v => xs)
191181pure = value
192182
193183syntax pureM [val] = with_val val (pure ())
194184
195−(<$>) : Eff m (a -> b) xs (\v => xs) ->
196− Eff m a xs (\v => xs) -> Eff m b xs (\v => xs)
185+(<$>) : Eff (a -> b) xs (\v => xs) ->
186+ Eff a xs (\v => xs) -> Eff b xs (\v => xs)
197187(<$>) prog v = do fn <- prog
198188 arg <- v
199189 return (fn arg)
@@ -213,20 +203,15 @@ execEff {e} {a} {res} {resk} (val :: env) (There p) eff k
213203-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
214204-- updates can be propagated even through failing computations?
215205
216−eff : Env m xs -> Eff m a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
206+eff : Env m xs -> Eff a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
217207eff env (value x) k = k x env
218−eff env (with_val x prog) k = eff env prog (\p', env' => k x env')
208+eff env (with_val x prog) k = eff env prog (\p', env' => k x env')
219209eff env (prog `ebind` c) k
220210 = eff env prog (\p', env' => eff env' (c p') k)
221211eff env (callP prf effP) k = execEff env prf effP k
222212eff env (liftP prf effP) k
223213 = let env' = dropEnv env prf in
224214 eff env' effP (\p', envk => k p' (rebuildEnv envk prf env))
225−eff env (newInit r prog) k
226− = eff (r :: env) prog (\p' => \ (v :: envk) => k p' envk)
227−eff env (catch prog handler) k
228− = catch (eff env prog k)
229− (\e => eff env (handler e) k)
230215-- FIXME:
231216-- xs is needed explicitly because otherwise the pattern binding for
232217-- 'l' appears too late. Solution seems to be to reorder patterns at the
@@ -249,84 +234,56 @@ syntax MkDefaultEnv = with Env
249234
250235call : {a, b: _} -> {e : Effect} ->
251236 (eff : e t a b) ->
252− {auto prf : EffElem e a xs} ->
253− Eff m t xs (\v => updateResTy v xs prf eff)
237+ {default tactics { search 100; }
238+ prf : EffElem e a xs} ->
239+ Eff t xs (\v => updateResTy v xs prf eff)
254240call e {prf} = callP prf e
255241
256242implicit
257−lift : Eff m t ys ys' ->
258− {auto prf : SubList ys xs} ->
259− Eff m t xs (\v => updateWith (ys' v) xs prf)
243+lift : Eff t ys ys' ->
244+ {default tactics { search 100; }
245+ prf : SubList ys xs} ->
246+ Eff t xs (\v => updateWith (ys' v) xs prf)
260247lift e {prf} = liftP prf e
261248
262249
263−new : Handler e m =>
264− {default default r : res} ->
265− Eff m a (MkEff res e :: xs) (\v => (MkEff res' e :: xs')) ->
266− Eff m a xs (\v => xs')
267−new {r} e = newInit r e
268−
269250-- --------------------------------------------------------- [ Running Effects ]
270251
271−||| Run an effectful program.
272−|||
273−||| The content (`m`) in which to run the program is taken from the environment in which the program is called.
274−||| The `env` argument is implicit and initialised automatically.
275−|||
276−||| @prog The effectful program to run.
277−run : Applicative m => {default MkDefaultEnv env : Env m xs} -> (prog : Eff m a xs xs') -> m a
252+||| Run an effectful program
253+run : Applicative m => {default MkDefaultEnv env : Env m xs} -> Eff a xs xs' -> m a
278254run {env} prog = eff env prog (\r, env => pure r)
279255
280−||| Run an effectful program in the identity context `id`.
281−|||
282−||| A helper function useful for when the given context is 'pure'.
283−||| The `env` argument is implicit and initialised automatically.
284−|||
285−||| @prog The effectful program to run.
286−runPure : {default MkDefaultEnv env : Env id xs} -> (prog : Eff id a xs xs') -> a
256+runPure : {default MkDefaultEnv env : Env id xs} -> Eff a xs xs' -> a
287257runPure {env} prog = eff env prog (\r, env => r)
288258
289−||| Run an effectful program with a default value for the environment context.
290−|||
291−||| This is useful for when no default value exists for a given resource type.
292−|||
293−||| @val The default value for the resource type.
294−||| @prog The effectful program to run.
295−runInit : Applicative m => (val : Env m xs) -> (prog : Eff m a xs xs') -> m a
259+runInit : Applicative m => Env m xs -> Eff a xs xs' -> m a
296260runInit env prog = eff env prog (\r, env => pure r)
297261
298−||| Run an effectful program in the identity context `id` with a given default value for the environment context.
299−|||
300−||| A helper function useful for when the given context is 'pure'.
301−|||
302−||| @val The default value for the resource type.
303−||| @prog The effectful program to run.
304−runPureInit : (val : Env id xs) -> (prog : Eff id a xs xs') -> a
262+runPureInit : Env id xs -> Eff a xs xs' -> a
305263runPureInit env prog = eff env prog (\r, env => r)
306264
307−runWith : (a -> m a) -> Env m xs -> Eff m a xs xs' -> m a
265+runWith : (a -> m a) -> Env m xs -> Eff a xs xs' -> m a
308266runWith inj env prog = eff env prog (\r, env => inj r)
309267
310−runEnv : Applicative m => Env m xs -> Eff m a xs xs' ->
268+runEnv : Applicative m => Env m xs -> Eff a xs xs' ->
311269 m (x : a ** Env m (xs' x))
312270runEnv env prog = eff env prog (\r, env => pure (r ** env))
313271
314272-- ----------------------------------------------- [ some higher order things ]
315273
316−mapE : Applicative m => (a -> {xs} Eff m b) -> List a -> {xs} Eff m (List b)
274+mapE : (a -> {xs} Eff b) -> List a -> {xs} Eff (List b)
317275mapE f [] = pure []
318276mapE f (x :: xs) = [| f x :: mapE f xs |]
319277
320278
321−mapVE : Applicative m =>
322− (a -> {xs} Eff m b) ->
323− Vect n a ->
324− {xs} Eff m (Vect n b)
279+mapVE : (a -> {xs} Eff b) ->
280+ Vect n a ->
281+ {xs} Eff (Vect n b)
325282mapVE f [] = pure []
326283mapVE f (x :: xs) = [| f x :: mapVE f xs |]
327284
328285
329−when : Applicative m => Bool -> Lazy ({xs} Eff m ()) -> {xs} Eff m ()
286+when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
330287when True e = Force e
331288when False e = pure ()
332289
libs/effects/Makefile+5−13
@@ -1,22 +1,14 @@
1−IDRIS := idris
2−
3−PKG := effects
1+IDRIS := idris
42
53build:
6− $(IDRIS) --build ${PKG}.ipkg
4+ $(IDRIS) --build effects.ipkg
75
86clean:
9− $(IDRIS) --clean ${PKG}.ipkg
7+ $(IDRIS) --clean effects.ipkg
108
119install:
12− $(IDRIS) --install ${PKG}.ipkg
10+ $(IDRIS) --install effects.ipkg
1311
1412rebuild: clean build
1513
16−doc:
17− $(IDRIS) --mkdoc ${PKG}.ipkg
18−
19−doc_clean:
20− rm -rf ${PKG}_doc
21−
22−.PHONY: build clean install rebuild doc doc_clean
14+.PHONY: build clean install rebuild
libs/neweffects/Makefiledeleted−14
@@ -1,14 +0,0 @@
1−IDRIS := idris
2−
3−build:
4− $(IDRIS) --build effects.ipkg
5−
6−clean:
7− $(IDRIS) --clean effects.ipkg
8−
9−install:
10− $(IDRIS) --install effects.ipkg
11−
12−rebuild: clean build
13−
14−.PHONY: build clean install rebuild
libs/neweffects/Effect/Default.idr → libs/oldeffects/Effect/Default.idrrenamed

The content is the same.

libs/neweffects/Effect/Exception.idr → libs/oldeffects/Effect/Exception.idrrenamed+1−1
@@ -26,7 +26,7 @@ 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 -> { [EXCEPTION a ] } Eff m b
3030raise err = call $ Raise err
3131
3232
libs/neweffects/Effect/File.idr → libs/oldeffects/Effect/File.idrrenamed+5−5
@@ -105,24 +105,24 @@ open : (fname : String)
105105 -> (m : Mode)
106106 -> { [FILE_IO ()] ==> [FILE_IO (if result
107107 then OpenFile m
108− else ())] } Eff Bool
108+ else ())] } Eff e Bool
109109open f m = call $ Open f m
110110
111111
112112||| Close a file.
113−close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff ()
113+close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff e ()
114114close = call $ Close
115115
116116||| Read a line from the file.
117−readLine : { [FILE_IO (OpenFile Read)] } Eff String
117+readLine : { [FILE_IO (OpenFile Read)] } Eff e String
118118readLine = call $ ReadLine
119119
120120||| Write a line to a file.
121−writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff ()
121+writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff e ()
122122writeLine str = call $ WriteLine str
123123
124124||| End of file?
125−eof : { [FILE_IO (OpenFile Read)] } Eff Bool
125+eof : { [FILE_IO (OpenFile Read)] } Eff e Bool
126126eof = call $ EOF
127127
128128-- --------------------------------------------------------------------- [ EOF ]
libs/neweffects/Effect/Memory.idr → libs/oldeffects/Effect/Memory.idrrenamed+8−8
@@ -101,7 +101,7 @@ RAW_MEMORY : Type -> EFFECT
101101RAW_MEMORY t = MkEff t RawMemory
102102
103103allocate : (n : Nat) ->
104− Eff () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
104+ Eff m () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
105105allocate size = call $ Allocate size
106106
107107initialize : {i : Nat} ->
@@ -109,18 +109,18 @@ initialize : {i : Nat} ->
109109 Bits8 ->
110110 (size : Nat) ->
111111 so (i + size <= n) ->
112− Eff () [RAW_MEMORY (MemoryChunk n i)]
112+ Eff m () [RAW_MEMORY (MemoryChunk n i)]
113113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
114114initialize c size prf = call $ Initialize c size prf
115115
116−free : Eff () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
116+free : Eff m () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
117117free = call Free
118118
119119peek : {i : Nat} ->
120120 (offset : Nat) ->
121121 (size : Nat) ->
122122 so (offset + size <= i) ->
123− { [RAW_MEMORY (MemoryChunk n i)] } Eff (Vect size Bits8)
123+ { [RAW_MEMORY (MemoryChunk n i)] } Eff m (Vect size Bits8)
124124peek offset size prf = call $ Peek offset size prf
125125
126126poke : {n : Nat} ->
@@ -128,12 +128,12 @@ poke : {n : Nat} ->
128128 (offset : Nat) ->
129129 Vect size Bits8 ->
130130 so (offset <= i && offset + size <= n) ->
131− Eff () [RAW_MEMORY (MemoryChunk n i)]
131+ Eff m () [RAW_MEMORY (MemoryChunk n i)]
132132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
133133poke offset content prf = call $ Poke offset content prf
134134
135135private
136−getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff (MemoryChunk n i)
136+getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff m (MemoryChunk n i)
137137getRawPtr = call $ GetRawPtr
138138
139139private
@@ -146,7 +146,7 @@ move' : {dst_size : Nat} ->
146146 (size : Nat) ->
147147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
148148 so (src_offset + size <= src_init) ->
149− Eff () [RAW_MEMORY (MemoryChunk dst_size dst_init)]
149+ Eff m () [RAW_MEMORY (MemoryChunk dst_size dst_init)]
150150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
151151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
152152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
@@ -162,7 +162,7 @@ move : {dst_size : Nat} ->
162162 (size : Nat) ->
163163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
164164 so (src_offset + size <= src_init) ->
165− Eff ()
165+ Eff m ()
166166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
167167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
168168 (\v =>
libs/neweffects/Effect/Monad.idr → libs/oldeffects/Effect/Monad.idrrenamed

The content is the same.

libs/neweffects/Effect/Random.idr → libs/oldeffects/Effect/Random.idrrenamed+5−5
@@ -17,14 +17,14 @@ RND : EFFECT
1717RND = MkEff Integer Random
1818
1919||| Generates a random Integer in a given range
20−rndInt : Integer -> Integer -> { [RND] } Eff Integer
20+rndInt : Integer -> Integer -> { [RND] } Eff m Integer
2121rndInt lower upper = do v <- call $ getRandom
2222 return (v `prim__sremBigInt` (upper - lower) + lower)
2323
2424||| Generate a random number in Fin (S `k`)
2525|||
2626||| Note that rndFin k takes values 0, 1, ..., k.
27−rndFin : (k : Nat) -> { [RND] } Eff (Fin (S k))
27+rndFin : (k : Nat) -> { [RND] } Eff m (Fin (S k))
2828rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
2929 return (toFin v)
3030 where toFin : Integer -> Fin (S k)
@@ -33,15 +33,15 @@ rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast
3333 Nothing => toFin (assert_smaller x (x - cast (S k)))
3434
3535||| Select a random element from a vector
36−rndSelect' : Vect (S k) a -> { [RND] } Eff a
36+rndSelect' : Vect (S k) a -> { [RND] } Eff IO a
3737rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
3838
3939||| Select a random element from a list, or Nothing if the list is empty
40−rndSelect : List a -> { [RND] } Eff (Maybe a)
40+rndSelect : List a -> { [RND] } Eff IO (Maybe a)
4141rndSelect [] = return Nothing
4242rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
4343
4444||| Sets the random seed
45−srand : Integer -> { [RND] } Eff ()
45+srand : Integer -> { [RND] } Eff m ()
4646srand n = call $ setSeed n
4747
libs/neweffects/Effect/Select.idr → libs/oldeffects/Effect/Select.idrrenamed+1−1
@@ -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 -> { [SELECT] } Eff m a
2222select xs = call $ Select xs
2323
libs/neweffects/Effect/State.idr → libs/oldeffects/Effect/State.idrrenamed+8−8
@@ -8,30 +8,30 @@ data State : Effect where
88 Get : { a } State a
99 Put : b -> { a ==> b } State ()
1010
11−-- using (m : Type -> Type)
12−instance Handler State m where
11+using (m : Type -> Type)
12+ instance Handler State m where
1313 handle st Get k = k st st
1414 handle st (Put n) k = k () n
1515
1616STATE : Type -> EFFECT
1717STATE t = MkEff t State
1818
19−get : { [STATE x] } Eff x
19+get : { [STATE x] } Eff m x
2020get = call $ Get
2121
22−put : x -> { [STATE x] } Eff ()
22+put : x -> { [STATE x] } Eff m ()
2323put val = call $ Put val
2424
25−putM : y -> { [STATE x] ==> [STATE y] } Eff ()
25+putM : y -> { [STATE x] ==> [STATE y] } Eff m ()
2626putM val = call $ Put val
2727
28−update : (x -> x) -> { [STATE x] } Eff ()
28+update : (x -> x) -> { [STATE x] } Eff m ()
2929update f = put (f !get)
3030
31−updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff ()
31+updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff m ()
3232updateM f = putM (f !get)
3333
34−locally : x -> ({ [STATE x] } Eff t) -> { [STATE y] } Eff t
34+locally : x -> ({ [STATE x] } Eff m t) -> { [STATE y] } Eff m t
3535locally newst prog = do st <- get
3636 putM newst
3737 val <- prog
libs/neweffects/Effect/StdIO.idr → libs/oldeffects/Effect/StdIO.idrrenamed+5−5
@@ -39,22 +39,22 @@ STDIO : EFFECT
3939STDIO = MkEff () StdIO
4040
4141||| Write a string to standard output.
42−putStr : String -> { [STDIO] } Eff ()
42+putStr : String -> { [STDIO] } Eff e ()
4343putStr s = call $ PutStr s
4444
4545||| Write a character to standard output.
46−putChar : Char -> { [STDIO] } Eff ()
46+putChar : Char -> { [STDIO] } Eff e ()
4747putChar c = call $ PutCh c
4848
4949||| Write a string to standard output, terminating with a newline.
50−putStrLn : String -> { [STDIO] } Eff ()
50+putStrLn : String -> { [STDIO] } Eff e ()
5151putStrLn s = putStr (s ++ "\n")
5252
5353||| Read a string from standard input.
54−getStr : { [STDIO] } Eff String
54+getStr : { [STDIO] } Eff e String
5555getStr = call $ GetStr
5656
5757||| Read a character from standard input.
58−getChar : { [STDIO] } Eff Char
58+getChar : { [STDIO] } Eff e Char
5959getChar = call $ GetCh
6060
libs/neweffects/Effect/System.idr → libs/oldeffects/Effect/System.idrrenamed+4−4
@@ -30,14 +30,14 @@ instance Handler System (IOExcept a) where
3030SYSTEM : EFFECT
3131SYSTEM = MkEff () System
3232
33−getArgs : { [SYSTEM] } Eff (List String)
33+getArgs : Handler System e => { [SYSTEM] } Eff e (List String)
3434getArgs = call Args
3535
36−time : { [SYSTEM] } Eff Int
36+time : Handler System e => { [SYSTEM] } Eff e Int
3737time = call Time
3838
39−getEnv : String -> { [SYSTEM] } Eff (Maybe String)
39+getEnv : Handler System e => String -> { [SYSTEM] } Eff e (Maybe String)
4040getEnv s = call $ GetEnv s
4141
42−system : String -> { [SYSTEM] } Eff Int
42+system : Handler System e => String -> { [SYSTEM] } Eff e Int
4343system s = call $ CSystem s
libs/neweffects/Effects.idr → libs/oldeffects/Effects.idrrenamed+102−59
@@ -10,7 +10,7 @@ import Effect.Default
1010%access public
1111-- ----------------------------------------------------------------- [ Effects ]
1212||| The Effect type describes effectful computations.
13−|||
13+|||
1414||| This type is parameterised by:
1515||| + The input resource.
1616||| + The return type of the computation.
@@ -28,11 +28,11 @@ data EFFECT : Type where
2828||| underlying computation context `m` for execution.
2929class Handler (e : Effect) (m : Type -> Type) where
3030 ||| How to handle the effect.
31− |||
31+ |||
3232 ||| @ r The resource being handled.
3333 ||| @ eff The effect to be applied.
3434 ||| @ k The continuation to pass the result of the effect
35− covering handle : (r : res) -> (eff : e t res resk) ->
35+ covering handle : (r : res) -> (eff : e t res resk) ->
3636 (k : ((x : t) -> resk x -> m a)) -> m a
3737
3838||| Get the resource type (handy at the REPL to find out about an effect)
@@ -48,27 +48,28 @@ resourceType (MkEff t e) = t
4848syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
4949
5050-- The state transition is dependent on a result `b`, a bound variable.
51−syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
51+syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
5252 = eff inst (\b => outst)
5353
5454--- A simple state transition
5555syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
5656
5757-- --------------------------------------- [ Properties and Proof Construction ]
58−data SubList : List a -> List a -> Type where
59− SubNil : SubList [] []
60− Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
61− Drop : SubList xs ys -> SubList xs (x :: ys)
58+using (xs : List a, ys : List a)
59+ data SubList : List a -> List a -> Type where
60+ SubNil : SubList {a} [] []
61+ Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
62+ Drop : SubList xs ys -> SubList xs (x :: ys)
6263
63−subListId : SubList xs xs
64−subListId {xs = Nil} = SubNil
65−subListId {xs = x :: xs} = Keep subListId
64+ subListId : SubList xs xs
65+ subListId {xs = Nil} = SubNil
66+ subListId {xs = x :: xs} = Keep subListId
6667
6768namespace Env
6869 data Env : (m : Type -> Type) -> List EFFECT -> Type where
6970 Nil : Env m Nil
7071 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
71−
72+
7273data EffElem : Effect -> Type ->
7374 List EFFECT -> Type where
7475 Here : EffElem x a (MkEff a x :: xs)
@@ -128,62 +129,71 @@ relabel {xs = []} l [] = []
128129relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
129130
130131-- ------------------------------------------------- [ The Language of Effects ]
131−||| Definition of a language of effectful programs.
132−|||
132+||| Definition of an Effect.
133+|||
134+||| @ m The computation context
133135||| @ x The return type of the result.
134136||| @ es The list of allowed side-effects.
135137||| @ ce Function to compute a new list of allowed side-effects.
136−data Eff : (x : Type)
138+data Eff : (m : Type -> Type)
139+ -> (x : Type)
137140 -> (es : List EFFECT)
138141 -> (ce : x -> List EFFECT) -> Type where
139− value : a -> Eff a xs (\v => xs)
140− with_val : (val : a) -> Eff () xs (\v => xs' val) ->
141− Eff a xs xs'
142− ebind : Eff a xs xs' ->
143− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
142+ value : a -> Eff m a xs (\v => xs)
143+ with_val : (val : a) -> Eff m () xs (\v => xs' val) ->
144+ Eff m a xs xs'
145+ ebind : Eff m a xs xs' ->
146+ ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
144147 callP : (prf : EffElem e a xs) ->
145148 (eff : e t a b) ->
146− Eff t xs (\v => updateResTy v xs prf eff)
149+ Eff m t xs (\v => updateResTy v xs prf eff)
147150
148151 liftP : (prf : SubList ys xs) ->
149− Eff t ys ys' -> Eff t xs (\v => updateWith (ys' v) xs prf)
150−
151− (:-) : (l : ty) ->
152− Eff t [x] xs' -> -- [x] (\v => xs) ->
153− Eff t [l ::: x] (\v => map (l :::) (xs' v))
154−
155−(>>=) : Eff a xs xs' ->
156− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
157−(>>=) = ebind
152+ Eff m t ys ys' -> Eff m t xs (\v => updateWith (ys' v) xs prf)
153+ newInit : Handler e m =>
154+ res ->
155+ Eff m a (MkEff res e :: xs) (\v => (MkEff res' e :: xs')) ->
156+ Eff m a xs (\v => xs')
157+ catch : Catchable m err =>
158+ Eff m a xs xs' -> (err -> Eff m a xs xs') ->
159+ Eff m a xs xs'
160+
161+ (:-) : (l : ty) ->
162+ Eff m t [x] xs' -> -- [x] (\v => xs) ->
163+ Eff m t [l ::: x] (\v => map (l :::) (xs' v))
164+
165+(>>=) : Eff m a xs xs' ->
166+ ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
167+(>>=) = ebind
158168
159169-- namespace SimpleBind
160−-- (>>=) : Eff m a xs (\v => xs) ->
170+-- (>>=) : Eff m a xs (\v => xs) ->
161171-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
162−-- (>>=) = ebind
172+-- (>>=) = ebind
163173
164174||| Run a subprogram which results in an effect state the same as the input.
165−staticEff : Eff a xs (\v => xs) -> Eff a xs (\v => xs)
175+staticEff : Eff m a xs (\v => xs) -> Eff m a xs (\v => xs)
166176staticEff = id
167177
168178||| Explicitly give the expected set of result effects for an effectful
169179||| operation.
170−toEff : .(xs' : List EFFECT) -> Eff a xs (\v => xs') -> Eff a xs (\v => xs')
180+toEff : .(xs' : List EFFECT) -> Eff m a xs (\v => xs') -> Eff m a xs (\v => xs')
171181toEff xs' = id
172182
173−return : a -> Eff a xs (\v => xs)
183+return : a -> Eff m a xs (\v => xs)
174184return x = value x
175185
176186-- ------------------------------------------------------ [ for idiom brackets ]
177187
178188infixl 2 <$>
179189
180−pure : a -> Eff a xs (\v => xs)
190+pure : a -> Eff m a xs (\v => xs)
181191pure = value
182192
183193syntax pureM [val] = with_val val (pure ())
184194
185−(<$>) : Eff (a -> b) xs (\v => xs) ->
186− Eff a xs (\v => xs) -> Eff b xs (\v => xs)
195+(<$>) : Eff m (a -> b) xs (\v => xs) ->
196+ Eff m a xs (\v => xs) -> Eff m b xs (\v => xs)
187197(<$>) prog v = do fn <- prog
188198 arg <- v
189199 return (fn arg)
@@ -203,15 +213,20 @@ execEff {e} {a} {res} {resk} (val :: env) (There p) eff k
203213-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
204214-- updates can be propagated even through failing computations?
205215
206−eff : Env m xs -> Eff a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
216+eff : Env m xs -> Eff m a xs xs' -> ((x : a) -> Env m (xs' x) -> m b) -> m b
207217eff env (value x) k = k x env
208−eff env (with_val x prog) k = eff env prog (\p', env' => k x env')
218+eff env (with_val x prog) k = eff env prog (\p', env' => k x env')
209219eff env (prog `ebind` c) k
210220 = eff env prog (\p', env' => eff env' (c p') k)
211221eff env (callP prf effP) k = execEff env prf effP k
212222eff env (liftP prf effP) k
213223 = let env' = dropEnv env prf in
214224 eff env' effP (\p', envk => k p' (rebuildEnv envk prf env))
225+eff env (newInit r prog) k
226+ = eff (r :: env) prog (\p' => \ (v :: envk) => k p' envk)
227+eff env (catch prog handler) k
228+ = catch (eff env prog k)
229+ (\e => eff env (handler e) k)
215230-- FIXME:
216231-- xs is needed explicitly because otherwise the pattern binding for
217232-- 'l' appears too late. Solution seems to be to reorder patterns at the
@@ -234,56 +249,84 @@ syntax MkDefaultEnv = with Env
234249
235250call : {a, b: _} -> {e : Effect} ->
236251 (eff : e t a b) ->
237− {default tactics { search 100; }
238− prf : EffElem e a xs} ->
239− Eff t xs (\v => updateResTy v xs prf eff)
252+ {auto prf : EffElem e a xs} ->
253+ Eff m t xs (\v => updateResTy v xs prf eff)
240254call e {prf} = callP prf e
241255
242256implicit
243−lift : Eff t ys ys' ->
244− {default tactics { search 100; }
245− prf : SubList ys xs} ->
246− Eff t xs (\v => updateWith (ys' v) xs prf)
257+lift : Eff m t ys ys' ->
258+ {auto prf : SubList ys xs} ->
259+ Eff m t xs (\v => updateWith (ys' v) xs prf)
247260lift e {prf} = liftP prf e
248261
249262
263+new : Handler e m =>
264+ {default default r : res} ->
265+ Eff m a (MkEff res e :: xs) (\v => (MkEff res' e :: xs')) ->
266+ Eff m a xs (\v => xs')
267+new {r} e = newInit r e
268+
250269-- --------------------------------------------------------- [ Running Effects ]
251270
252−||| Run an effectful program
253−run : Applicative m => {default MkDefaultEnv env : Env m xs} -> Eff a xs xs' -> m a
271+||| Run an effectful program.
272+|||
273+||| The content (`m`) in which to run the program is taken from the environment in which the program is called.
274+||| The `env` argument is implicit and initialised automatically.
275+|||
276+||| @prog The effectful program to run.
277+run : Applicative m => {default MkDefaultEnv env : Env m xs} -> (prog : Eff m a xs xs') -> m a
254278run {env} prog = eff env prog (\r, env => pure r)
255279
256−runPure : {default MkDefaultEnv env : Env id xs} -> Eff a xs xs' -> a
280+||| Run an effectful program in the identity context `id`.
281+|||
282+||| A helper function useful for when the given context is 'pure'.
283+||| The `env` argument is implicit and initialised automatically.
284+|||
285+||| @prog The effectful program to run.
286+runPure : {default MkDefaultEnv env : Env id xs} -> (prog : Eff id a xs xs') -> a
257287runPure {env} prog = eff env prog (\r, env => r)
258288
259−runInit : Applicative m => Env m xs -> Eff a xs xs' -> m a
289+||| Run an effectful program with a default value for the environment context.
290+|||
291+||| This is useful for when no default value exists for a given resource type.
292+|||
293+||| @val The default value for the resource type.
294+||| @prog The effectful program to run.
295+runInit : Applicative m => (val : Env m xs) -> (prog : Eff m a xs xs') -> m a
260296runInit env prog = eff env prog (\r, env => pure r)
261297
262−runPureInit : Env id xs -> Eff a xs xs' -> a
298+||| Run an effectful program in the identity context `id` with a given default value for the environment context.
299+|||
300+||| A helper function useful for when the given context is 'pure'.
301+|||
302+||| @val The default value for the resource type.
303+||| @prog The effectful program to run.
304+runPureInit : (val : Env id xs) -> (prog : Eff id a xs xs') -> a
263305runPureInit env prog = eff env prog (\r, env => r)
264306
265−runWith : (a -> m a) -> Env m xs -> Eff a xs xs' -> m a
307+runWith : (a -> m a) -> Env m xs -> Eff m a xs xs' -> m a
266308runWith inj env prog = eff env prog (\r, env => inj r)
267309
268−runEnv : Applicative m => Env m xs -> Eff a xs xs' ->
310+runEnv : Applicative m => Env m xs -> Eff m a xs xs' ->
269311 m (x : a ** Env m (xs' x))
270312runEnv env prog = eff env prog (\r, env => pure (r ** env))
271313
272314-- ----------------------------------------------- [ some higher order things ]
273315
274−mapE : (a -> {xs} Eff b) -> List a -> {xs} Eff (List b)
316+mapE : Applicative m => (a -> {xs} Eff m b) -> List a -> {xs} Eff m (List b)
275317mapE f [] = pure []
276318mapE f (x :: xs) = [| f x :: mapE f xs |]
277319
278320
279−mapVE : (a -> {xs} Eff b) ->
280− Vect n a ->
281− {xs} Eff (Vect n b)
321+mapVE : Applicative m =>
322+ (a -> {xs} Eff m b) ->
323+ Vect n a ->
324+ {xs} Eff m (Vect n b)
282325mapVE f [] = pure []
283326mapVE f (x :: xs) = [| f x :: mapVE f xs |]
284327
285328
286−when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
329+when : Applicative m => Bool -> Lazy ({xs} Eff m ()) -> {xs} Eff m ()
287330when True e = Force e
288331when False e = pure ()
289332
libs/oldeffects/Makefilenew file+22
@@ -0,0 +1,22 @@
1+IDRIS := idris
2+
3+PKG := effects
4+
5+build:
6+ $(IDRIS) --build ${PKG}.ipkg
7+
8+clean:
9+ $(IDRIS) --clean ${PKG}.ipkg
10+
11+install:
12+ $(IDRIS) --install ${PKG}.ipkg
13+
14+rebuild: clean build
15+
16+doc:
17+ $(IDRIS) --mkdoc ${PKG}.ipkg
18+
19+doc_clean:
20+ rm -rf ${PKG}_doc
21+
22+.PHONY: build clean install rebuild doc doc_clean
libs/neweffects/effects.ipkg → libs/oldeffects/effects.ipkgrenamed+1−1
@@ -1,4 +1,4 @@
1−package neweffects
1+package oldeffects
22
33opts = "--nobasepkgs -i ../prelude -i ../base"
44modules = Effects, Effect.Default,
test/effects001/test021.idr+1−1
@@ -9,7 +9,7 @@ data Count : Type where
99
1010FileIO : Type -> Type -> Type
1111FileIO st t
12− = { [FILE_IO st, STDIO, Count ::: STATE Int] } Eff IO t
12+ = { [FILE_IO st, STDIO, Count ::: STATE Int] } Eff t
1313
1414readFile : FileIO (OpenFile Read) (List String)
1515readFile = readAcc [] where
test/effects001/test021a.idr+1−1
@@ -17,7 +17,7 @@ Env = List (String, Integer)
1717-- Evaluator t
1818-- = Eff m [EXCEPTION String, RND, STATE Env] t
1919
20−eval : Expr -> { [EXCEPTION String, STDIO, RND, STATE Env] } Eff IO Integer
20+eval : Expr -> { [EXCEPTION String, STDIO, RND, STATE Env] } Eff Integer
2121eval (Var x) = do vs <- get
2222 case lookup x vs of
2323 Nothing => raise ("No such variable " ++ x)
test/effects002/test025.idr+1−1
@@ -6,7 +6,7 @@ import Control.IOExcept
66
77MemoryIO : Type -> Type -> Type -> Type
88MemoryIO td ts r = { [ Dst ::: RAW_MEMORY td
9− , Src ::: RAW_MEMORY ts ] } Eff (IOExcept String) r
9+ , Src ::: RAW_MEMORY ts ] } Eff r
1010
1111inpVect : Vect 5 Bits8
1212inpVect = map prim__truncInt_B8 [0, 1, 2, 3, 5]