on master help sign in
Replace 'effects' with neweffects
ced7733Edwin Brady
CHANGELOG+1−1
@@ -7,7 +7,7 @@ New in 0.9.14:
7* Clearly distinguish between type providers and postulate providers at the use site
7* Clearly distinguish between type providers and postulate providers at the use site
8* Allow dependent function syntax to be overridden in dsl blocks, similarly to
8* Allow dependent function syntax to be overridden in dsl blocks, similarly to
9 functions and let. The keyword for this is "pi".
9 functions and let. The keyword for this is "pi".
10−* Experimental 'neweffects' library, with simplified API
10+* Updated 'effects' library, with simplified API
11* All new JavaScript backend (avoids callstack overflows)
11* All new JavaScript backend (avoids callstack overflows)
12* Add support for %lib directive for NodeJS
12* Add support for %lib directive for NodeJS
13* Quasiquotes and quasiquote patterns allow easier work with reflected terms.
13* Quasiquotes and quasiquote patterns allow easier work with reflected terms.
libs/Makefile−5
@@ -2,32 +2,27 @@ build:
2 $(MAKE) -C prelude build
2 $(MAKE) -C prelude build
3 $(MAKE) -C base build
3 $(MAKE) -C base build
4 $(MAKE) -C effects build
4 $(MAKE) -C effects build
5− $(MAKE) -C neweffects build
6
5
7
6
8install:
7install:
9 $(MAKE) -C prelude install
8 $(MAKE) -C prelude install
10 $(MAKE) -C base install
9 $(MAKE) -C base install
11 $(MAKE) -C effects install
10 $(MAKE) -C effects install
12− $(MAKE) -C neweffects install
13
11
14clean:
12clean:
15 $(MAKE) -C prelude clean
13 $(MAKE) -C prelude clean
16 $(MAKE) -C base clean
14 $(MAKE) -C base clean
17 $(MAKE) -C effects clean
15 $(MAKE) -C effects clean
18− $(MAKE) -C neweffects clean
19
16
20doc:
17doc:
21 $(MAKE) -C prelude doc
18 $(MAKE) -C prelude doc
22 $(MAKE) -C base doc
19 $(MAKE) -C base doc
23 $(MAKE) -C effects doc
20 $(MAKE) -C effects doc
24− $(MAKE) -C neweffects doc
25
21
26doc_clean:
22doc_clean:
27 $(MAKE) -C prelude doc_clean
23 $(MAKE) -C prelude doc_clean
28 $(MAKE) -C base doc_clean
24 $(MAKE) -C base doc_clean
29 $(MAKE) -C effects doc_clean
25 $(MAKE) -C effects doc_clean
30− $(MAKE) -C neweffects doc_clean
31
26
32
27
33.PHONY: build install clean doc doc_clean
28.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
26EXCEPTION : Type -> EFFECT
26EXCEPTION : Type -> EFFECT
27EXCEPTION t = MkEff () (Exception t)
27EXCEPTION t = MkEff () (Exception t)
28
28
29−raise : a -> { [EXCEPTION a ] } Eff m b
29+raise : a -> { [EXCEPTION a ] } Eff b
30raise err = call $ Raise err
30raise err = call $ Raise err
31
31
32
32
libs/effects/Effect/File.idr+5−5
@@ -105,24 +105,24 @@ open : (fname : String)
105 -> (m : Mode)
105 -> (m : Mode)
106 -> { [FILE_IO ()] ==> [FILE_IO (if result
106 -> { [FILE_IO ()] ==> [FILE_IO (if result
107 then OpenFile m
107 then OpenFile m
108− else ())] } Eff e Bool
108+ else ())] } Eff Bool
109open f m = call $ Open f m
109open f m = call $ Open f m
110
110
111
111
112||| Close a file.
112||| Close a file.
113−close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff e ()
113+close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff ()
114close = call $ Close
114close = call $ Close
115
115
116||| Read a line from the file.
116||| Read a line from the file.
117−readLine : { [FILE_IO (OpenFile Read)] } Eff e String
117+readLine : { [FILE_IO (OpenFile Read)] } Eff String
118readLine = call $ ReadLine
118readLine = call $ ReadLine
119
119
120||| Write a line to a file.
120||| Write a line to a file.
121−writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff e ()
121+writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff ()
122writeLine str = call $ WriteLine str
122writeLine str = call $ WriteLine str
123
123
124||| End of file?
124||| End of file?
125−eof : { [FILE_IO (OpenFile Read)] } Eff e Bool
125+eof : { [FILE_IO (OpenFile Read)] } Eff Bool
126eof = call $ EOF
126eof = call $ EOF
127
127
128-- --------------------------------------------------------------------- [ EOF ]
128-- --------------------------------------------------------------------- [ EOF ]
libs/effects/Effect/Memory.idr+8−8
@@ -101,7 +101,7 @@ RAW_MEMORY : Type -> EFFECT
101RAW_MEMORY t = MkEff t RawMemory
101RAW_MEMORY t = MkEff t RawMemory
102
102
103allocate : (n : Nat) ->
103allocate : (n : Nat) ->
104− Eff m () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
104+ Eff () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
105allocate size = call $ Allocate size
105allocate size = call $ Allocate size
106
106
107initialize : {i : Nat} ->
107initialize : {i : Nat} ->
@@ -109,18 +109,18 @@ initialize : {i : Nat} ->
109 Bits8 ->
109 Bits8 ->
110 (size : Nat) ->
110 (size : Nat) ->
111 so (i + size <= n) ->
111 so (i + size <= n) ->
112− Eff m () [RAW_MEMORY (MemoryChunk n i)]
112+ Eff () [RAW_MEMORY (MemoryChunk n i)]
113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
114initialize c size prf = call $ Initialize c size prf
114initialize c size prf = call $ Initialize c size prf
115
115
116−free : Eff m () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
116+free : Eff () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
117free = call Free
117free = call Free
118
118
119peek : {i : Nat} ->
119peek : {i : Nat} ->
120 (offset : Nat) ->
120 (offset : Nat) ->
121 (size : Nat) ->
121 (size : Nat) ->
122 so (offset + size <= i) ->
122 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)
124peek offset size prf = call $ Peek offset size prf
124peek offset size prf = call $ Peek offset size prf
125
125
126poke : {n : Nat} ->
126poke : {n : Nat} ->
@@ -128,12 +128,12 @@ poke : {n : Nat} ->
128 (offset : Nat) ->
128 (offset : Nat) ->
129 Vect size Bits8 ->
129 Vect size Bits8 ->
130 so (offset <= i && offset + size <= n) ->
130 so (offset <= i && offset + size <= n) ->
131− Eff m () [RAW_MEMORY (MemoryChunk n i)]
131+ Eff () [RAW_MEMORY (MemoryChunk n i)]
132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
133poke offset content prf = call $ Poke offset content prf
133poke offset content prf = call $ Poke offset content prf
134
134
135private
135private
136−getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff m (MemoryChunk n i)
136+getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff (MemoryChunk n i)
137getRawPtr = call $ GetRawPtr
137getRawPtr = call $ GetRawPtr
138
138
139private
139private
@@ -146,7 +146,7 @@ move' : {dst_size : Nat} ->
146 (size : Nat) ->
146 (size : Nat) ->
147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
148 so (src_offset + size <= src_init) ->
148 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)]
150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
@@ -162,7 +162,7 @@ move : {dst_size : Nat} ->
162 (size : Nat) ->
162 (size : Nat) ->
163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
164 so (src_offset + size <= src_init) ->
164 so (src_offset + size <= src_init) ->
165− Eff m ()
165+ Eff ()
166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
168 (\v =>
168 (\v =>
libs/effects/Effect/Random.idr+5−5
@@ -17,14 +17,14 @@ RND : EFFECT
17RND = MkEff Integer Random
17RND = MkEff Integer Random
18
18
19||| Generates a random Integer in a given range
19||| Generates a random Integer in a given range
20−rndInt : Integer -> Integer -> { [RND] } Eff m Integer
20+rndInt : Integer -> Integer -> { [RND] } Eff Integer
21rndInt lower upper = do v <- call $ getRandom
21rndInt lower upper = do v <- call $ getRandom
22 return (v `prim__sremBigInt` (upper - lower) + lower)
22 return (v `prim__sremBigInt` (upper - lower) + lower)
23
23
24||| Generate a random number in Fin (S `k`)
24||| Generate a random number in Fin (S `k`)
25|||
25|||
26||| Note that rndFin k takes values 0, 1, ..., k.
26||| 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))
28rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
28rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
29 return (toFin v)
29 return (toFin v)
30 where toFin : Integer -> Fin (S k)
30 where toFin : Integer -> Fin (S k)
@@ -33,15 +33,15 @@ rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast
33 Nothing => toFin (assert_smaller x (x - cast (S k)))
33 Nothing => toFin (assert_smaller x (x - cast (S k)))
34
34
35||| Select a random element from a vector
35||| 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
37rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
37rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
38
38
39||| Select a random element from a list, or Nothing if the list is empty
39||| 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)
41rndSelect [] = return Nothing
41rndSelect [] = return Nothing
42rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
42rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
43
43
44||| Sets the random seed
44||| Sets the random seed
45−srand : Integer -> { [RND] } Eff m ()
45+srand : Integer -> { [RND] } Eff ()
46srand n = call $ setSeed n
46srand n = call $ setSeed n
47
47
libs/effects/Effect/Select.idr+1−1
@@ -18,6 +18,6 @@ instance Handler Selection List where
18SELECT : EFFECT
18SELECT : EFFECT
19SELECT = MkEff () Selection
19SELECT = MkEff () Selection
20
20
21−select : List a -> { [SELECT] } Eff m a
21+select : List a -> { [SELECT] } Eff a
22select xs = call $ Select xs
22select xs = call $ Select xs
23
23
libs/effects/Effect/State.idr+8−8
@@ -8,30 +8,30 @@ data State : Effect where
8 Get : { a } State a
8 Get : { a } State a
9 Put : b -> { a ==> b } State ()
9 Put : b -> { a ==> b } State ()
10
10
11−using (m : Type -> Type)
11+-- using (m : Type -> Type)
12− instance Handler State m where
12+instance Handler State m where
13 handle st Get k = k st st
13 handle st Get k = k st st
14 handle st (Put n) k = k () n
14 handle st (Put n) k = k () n
15
15
16STATE : Type -> EFFECT
16STATE : Type -> EFFECT
17STATE t = MkEff t State
17STATE t = MkEff t State
18
18
19−get : { [STATE x] } Eff m x
19+get : { [STATE x] } Eff x
20get = call $ Get
20get = call $ Get
21
21
22−put : x -> { [STATE x] } Eff m ()
22+put : x -> { [STATE x] } Eff ()
23put val = call $ Put val
23put val = call $ Put val
24
24
25−putM : y -> { [STATE x] ==> [STATE y] } Eff m ()
25+putM : y -> { [STATE x] ==> [STATE y] } Eff ()
26putM val = call $ Put val
26putM val = call $ Put val
27
27
28−update : (x -> x) -> { [STATE x] } Eff m ()
28+update : (x -> x) -> { [STATE x] } Eff ()
29update f = put (f !get)
29update f = put (f !get)
30
30
31−updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff m ()
31+updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff ()
32updateM f = putM (f !get)
32updateM f = putM (f !get)
33
33
34−locally : x -> ({ [STATE x] } Eff m t) -> { [STATE y] } Eff m t
34+locally : x -> ({ [STATE x] } Eff t) -> { [STATE y] } Eff t
35locally newst prog = do st <- get
35locally newst prog = do st <- get
36 putM newst
36 putM newst
37 val <- prog
37 val <- prog
libs/effects/Effect/StdIO.idr+5−5
@@ -39,22 +39,22 @@ STDIO : EFFECT
39STDIO = MkEff () StdIO
39STDIO = MkEff () StdIO
40
40
41||| Write a string to standard output.
41||| Write a string to standard output.
42−putStr : String -> { [STDIO] } Eff e ()
42+putStr : String -> { [STDIO] } Eff ()
43putStr s = call $ PutStr s
43putStr s = call $ PutStr s
44
44
45||| Write a character to standard output.
45||| Write a character to standard output.
46−putChar : Char -> { [STDIO] } Eff e ()
46+putChar : Char -> { [STDIO] } Eff ()
47putChar c = call $ PutCh c
47putChar c = call $ PutCh c
48
48
49||| Write a string to standard output, terminating with a newline.
49||| Write a string to standard output, terminating with a newline.
50−putStrLn : String -> { [STDIO] } Eff e ()
50+putStrLn : String -> { [STDIO] } Eff ()
51putStrLn s = putStr (s ++ "\n")
51putStrLn s = putStr (s ++ "\n")
52
52
53||| Read a string from standard input.
53||| Read a string from standard input.
54−getStr : { [STDIO] } Eff e String
54+getStr : { [STDIO] } Eff String
55getStr = call $ GetStr
55getStr = call $ GetStr
56
56
57||| Read a character from standard input.
57||| Read a character from standard input.
58−getChar : { [STDIO] } Eff e Char
58+getChar : { [STDIO] } Eff Char
59getChar = call $ GetCh
59getChar = call $ GetCh
60
60
libs/effects/Effect/System.idr+4−4
@@ -30,14 +30,14 @@ instance Handler System (IOExcept a) where
30SYSTEM : EFFECT
30SYSTEM : EFFECT
31SYSTEM = MkEff () System
31SYSTEM = MkEff () System
32
32
33−getArgs : Handler System e => { [SYSTEM] } Eff e (List String)
33+getArgs : { [SYSTEM] } Eff (List String)
34getArgs = call Args
34getArgs = call Args
35
35
36−time : Handler System e => { [SYSTEM] } Eff e Int
36+time : { [SYSTEM] } Eff Int
37time = call Time
37time = call Time
38
38
39−getEnv : Handler System e => String -> { [SYSTEM] } Eff e (Maybe String)
39+getEnv : String -> { [SYSTEM] } Eff (Maybe String)
40getEnv s = call $ GetEnv s
40getEnv s = call $ GetEnv s
41
41
42−system : Handler System e => String -> { [SYSTEM] } Eff e Int
42+system : String -> { [SYSTEM] } Eff Int
43system s = call $ CSystem s
43system s = call $ CSystem s
libs/effects/Effects.idr+59−102
@@ -10,7 +10,7 @@ import Effect.Default
10%access public
10%access public
11-- ----------------------------------------------------------------- [ Effects ]
11-- ----------------------------------------------------------------- [ Effects ]
12||| The Effect type describes effectful computations.
12||| The Effect type describes effectful computations.
13−|||
13+|||
14||| This type is parameterised by:
14||| This type is parameterised by:
15||| + The input resource.
15||| + The input resource.
16||| + The return type of the computation.
16||| + The return type of the computation.
@@ -28,11 +28,11 @@ data EFFECT : Type where
28||| underlying computation context `m` for execution.
28||| underlying computation context `m` for execution.
29class Handler (e : Effect) (m : Type -> Type) where
29class Handler (e : Effect) (m : Type -> Type) where
30 ||| How to handle the effect.
30 ||| How to handle the effect.
31− |||
31+ |||
32 ||| @ r The resource being handled.
32 ||| @ r The resource being handled.
33 ||| @ eff The effect to be applied.
33 ||| @ eff The effect to be applied.
34 ||| @ k The continuation to pass the result of the effect
34 ||| @ 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) ->
36 (k : ((x : t) -> resk x -> m a)) -> m a
36 (k : ((x : t) -> resk x -> m a)) -> m a
37
37
38||| Get the resource type (handy at the REPL to find out about an effect)
38||| Get the resource type (handy at the REPL to find out about an effect)
@@ -48,28 +48,27 @@ resourceType (MkEff t e) = t
48syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
48syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
49
49
50-- The state transition is dependent on a result `b`, a bound variable.
50-- The state transition is dependent on a result `b`, a bound variable.
51−syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
51+syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
52 = eff inst (\b => outst)
52 = eff inst (\b => outst)
53
53
54--- A simple state transition
54--- A simple state transition
55syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
55syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
56
56
57-- --------------------------------------- [ Properties and Proof Construction ]
57-- --------------------------------------- [ Properties and Proof Construction ]
58−using (xs : List a, ys : List a)
59− data SubList : List a -> List a -> Type where
58+data SubList : List a -> List a -> Type where
60− SubNil : SubList {a} [] []
59+ SubNil : SubList [] []
61− Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
60+ Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
62− Drop : SubList xs ys -> SubList xs (x :: ys)
61+ Drop : SubList xs ys -> SubList xs (x :: ys)
63
62
64− subListId : SubList xs xs
63+subListId : SubList xs xs
65− subListId {xs = Nil} = SubNil
64+subListId {xs = Nil} = SubNil
66− subListId {xs = x :: xs} = Keep subListId
65+subListId {xs = x :: xs} = Keep subListId
67
66
68namespace Env
67namespace Env
69 data Env : (m : Type -> Type) -> List EFFECT -> Type where
68 data Env : (m : Type -> Type) -> List EFFECT -> Type where
70 Nil : Env m Nil
69 Nil : Env m Nil
71 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
70 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
72−
71+
73data EffElem : Effect -> Type ->
72data EffElem : Effect -> Type ->
74 List EFFECT -> Type where
73 List EFFECT -> Type where
75 Here : EffElem x a (MkEff a x :: xs)
74 Here : EffElem x a (MkEff a x :: xs)
@@ -129,71 +128,62 @@ relabel {xs = []} l [] = []
129relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
128relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
130
129
131-- ------------------------------------------------- [ The Language of Effects ]
130-- ------------------------------------------------- [ The Language of Effects ]
132−||| Definition of an Effect.
131+||| Definition of a language of effectful programs.
133−|||
132+|||
134−||| @ m The computation context
135||| @ x The return type of the result.
133||| @ x The return type of the result.
136||| @ es The list of allowed side-effects.
134||| @ es The list of allowed side-effects.
137||| @ ce Function to compute a new list of allowed side-effects.
135||| @ 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)
140 -> (es : List EFFECT)
137 -> (es : List EFFECT)
141 -> (ce : x -> List EFFECT) -> Type where
138 -> (ce : x -> List EFFECT) -> Type where
142− value : a -> Eff m a xs (\v => xs)
139+ value : a -> Eff a xs (\v => xs)
143− with_val : (val : a) -> Eff m () xs (\v => xs' val) ->
140+ with_val : (val : a) -> Eff () xs (\v => xs' val) ->
144− Eff m a xs xs'
141+ Eff a xs xs'
145− ebind : Eff m a xs xs' ->
142+ ebind : Eff a xs xs' ->
146− ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
143+ ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
147 callP : (prf : EffElem e a xs) ->
144 callP : (prf : EffElem e a xs) ->
148 (eff : e t a b) ->
145 (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)
150
147
151 liftP : (prf : SubList ys xs) ->
148 liftP : (prf : SubList ys xs) ->
152− Eff m t ys ys' -> Eff m t xs (\v => updateWith (ys' v) xs prf)
149+ Eff t ys ys' -> Eff t xs (\v => updateWith (ys' v) xs prf)
153− newInit : Handler e m =>
150+
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) ->
151+ (:-) : (l : ty) ->
162− Eff m t [x] xs' -> -- [x] (\v => xs) ->
152+ Eff t [x] xs' -> -- [x] (\v => xs) ->
163− Eff m t [l ::: x] (\v => map (l :::) (xs' v))
153+ Eff t [l ::: x] (\v => map (l :::) (xs' v))
164−
154+
165−(>>=) : Eff m a xs xs' ->
155+(>>=) : Eff a xs xs' ->
166− ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
156+ ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
167−(>>=) = ebind
157+(>>=) = ebind
168
158
169-- namespace SimpleBind
159-- namespace SimpleBind
170−-- (>>=) : Eff m a xs (\v => xs) ->
160+-- (>>=) : Eff m a xs (\v => xs) ->
171-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
161-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
172−-- (>>=) = ebind
162+-- (>>=) = ebind
173
163
174||| Run a subprogram which results in an effect state the same as the input.
164||| 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)
176staticEff = id
166staticEff = id
177
167
178||| Explicitly give the expected set of result effects for an effectful
168||| Explicitly give the expected set of result effects for an effectful
179||| operation.
169||| 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')
181toEff xs' = id
171toEff xs' = id
182
172
183−return : a -> Eff m a xs (\v => xs)
173+return : a -> Eff a xs (\v => xs)
184return x = value x
174return x = value x
185
175
186-- ------------------------------------------------------ [ for idiom brackets ]
176-- ------------------------------------------------------ [ for idiom brackets ]
187
177
188infixl 2 <$>
178infixl 2 <$>
189
179
190−pure : a -> Eff m a xs (\v => xs)
180+pure : a -> Eff a xs (\v => xs)
191pure = value
181pure = value
192
182
193syntax pureM [val] = with_val val (pure ())
183syntax pureM [val] = with_val val (pure ())
194
184
195−(<$>) : Eff m (a -> b) xs (\v => xs) ->
185+(<$>) : Eff (a -> b) xs (\v => xs) ->
196− Eff m a xs (\v => xs) -> Eff m b xs (\v => xs)
186+ Eff a xs (\v => xs) -> Eff b xs (\v => xs)
197(<$>) prog v = do fn <- prog
187(<$>) prog v = do fn <- prog
198 arg <- v
188 arg <- v
199 return (fn arg)
189 return (fn arg)
@@ -213,20 +203,15 @@ execEff {e} {a} {res} {resk} (val :: env) (There p) eff k
213-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
203-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
214-- updates can be propagated even through failing computations?
204-- updates can be propagated even through failing computations?
215
205
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
217eff env (value x) k = k x env
207eff 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')
219eff env (prog `ebind` c) k
209eff env (prog `ebind` c) k
220 = eff env prog (\p', env' => eff env' (c p') k)
210 = eff env prog (\p', env' => eff env' (c p') k)
221eff env (callP prf effP) k = execEff env prf effP k
211eff env (callP prf effP) k = execEff env prf effP k
222eff env (liftP prf effP) k
212eff env (liftP prf effP) k
223 = let env' = dropEnv env prf in
213 = let env' = dropEnv env prf in
224 eff env' effP (\p', envk => k p' (rebuildEnv envk prf env))
214 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)
230-- FIXME:
215-- FIXME:
231-- xs is needed explicitly because otherwise the pattern binding for
216-- xs is needed explicitly because otherwise the pattern binding for
232-- 'l' appears too late. Solution seems to be to reorder patterns at the
217-- 'l' appears too late. Solution seems to be to reorder patterns at the
@@ -249,84 +234,56 @@ syntax MkDefaultEnv = with Env
249
234
250call : {a, b: _} -> {e : Effect} ->
235call : {a, b: _} -> {e : Effect} ->
251 (eff : e t a b) ->
236 (eff : e t a b) ->
237+ {default tactics { search 100; }
252− {auto prf : EffElem e a xs} ->
238+ prf : EffElem e a xs} ->
253− Eff m t xs (\v => updateResTy v xs prf eff)
239+ Eff t xs (\v => updateResTy v xs prf eff)
254call e {prf} = callP prf e
240call e {prf} = callP prf e
255
241
256implicit
242implicit
257−lift : Eff m t ys ys' ->
243+lift : Eff t ys ys' ->
244+ {default tactics { search 100; }
258− {auto prf : SubList ys xs} ->
245+ prf : SubList ys xs} ->
259− Eff m t xs (\v => updateWith (ys' v) xs prf)
246+ Eff t xs (\v => updateWith (ys' v) xs prf)
260lift e {prf} = liftP prf e
247lift e {prf} = liftP prf e
261
248
262
249
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−
269-- --------------------------------------------------------- [ Running Effects ]
250-- --------------------------------------------------------- [ Running Effects ]
270
251
271−||| Run an effectful program.
252+||| 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
253+run : Applicative m => {default MkDefaultEnv env : Env m xs} -> Eff a xs xs' -> m a
278run {env} prog = eff env prog (\r, env => pure r)
254run {env} prog = eff env prog (\r, env => pure r)
279
255
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
287runPure {env} prog = eff env prog (\r, env => r)
257runPure {env} prog = eff env prog (\r, env => r)
288
258
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
296runInit env prog = eff env prog (\r, env => pure r)
260runInit env prog = eff env prog (\r, env => pure r)
297
261
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
305runPureInit env prog = eff env prog (\r, env => r)
263runPureInit env prog = eff env prog (\r, env => r)
306
264
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
308runWith inj env prog = eff env prog (\r, env => inj r)
266runWith inj env prog = eff env prog (\r, env => inj r)
309
267
310−runEnv : Applicative m => Env m xs -> Eff m a xs xs' ->
268+runEnv : Applicative m => Env m xs -> Eff a xs xs' ->
311 m (x : a ** Env m (xs' x))
269 m (x : a ** Env m (xs' x))
312runEnv env prog = eff env prog (\r, env => pure (r ** env))
270runEnv env prog = eff env prog (\r, env => pure (r ** env))
313
271
314-- ----------------------------------------------- [ some higher order things ]
272-- ----------------------------------------------- [ some higher order things ]
315
273
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)
317mapE f [] = pure []
275mapE f [] = pure []
318mapE f (x :: xs) = [| f x :: mapE f xs |]
276mapE f (x :: xs) = [| f x :: mapE f xs |]
319
277
320
278
321−mapVE : Applicative m =>
322− (a -> {xs} Eff m b) ->
279+mapVE : (a -> {xs} Eff b) ->
323− Vect n a ->
280+ Vect n a ->
324− {xs} Eff m (Vect n b)
281+ {xs} Eff (Vect n b)
325mapVE f [] = pure []
282mapVE f [] = pure []
326mapVE f (x :: xs) = [| f x :: mapVE f xs |]
283mapVE f (x :: xs) = [| f x :: mapVE f xs |]
327
284
328
285
329−when : Applicative m => Bool -> Lazy ({xs} Eff m ()) -> {xs} Eff m ()
286+when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
330when True e = Force e
287when True e = Force e
331when False e = pure ()
288when False e = pure ()
332
289
libs/effects/Makefile+5−13
@@ -1,22 +1,14 @@
1−IDRIS := idris
1+IDRIS := idris
2−
3−PKG := effects
4
2
5build:
3build:
6− $(IDRIS) --build ${PKG}.ipkg
4+ $(IDRIS) --build effects.ipkg
7
5
8clean:
6clean:
9− $(IDRIS) --clean ${PKG}.ipkg
7+ $(IDRIS) --clean effects.ipkg
10
8
11install:
9install:
12− $(IDRIS) --install ${PKG}.ipkg
10+ $(IDRIS) --install effects.ipkg
13
11
14rebuild: clean build
12rebuild: clean build
15
13
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
26EXCEPTION : Type -> EFFECT
26EXCEPTION : Type -> EFFECT
27EXCEPTION t = MkEff () (Exception t)
27EXCEPTION t = MkEff () (Exception t)
28
28
29−raise : a -> { [EXCEPTION a ] } Eff b
29+raise : a -> { [EXCEPTION a ] } Eff m b
30raise err = call $ Raise err
30raise err = call $ Raise err
31
31
32
32
libs/neweffects/Effect/File.idr → libs/oldeffects/Effect/File.idrrenamed+5−5
@@ -105,24 +105,24 @@ open : (fname : String)
105 -> (m : Mode)
105 -> (m : Mode)
106 -> { [FILE_IO ()] ==> [FILE_IO (if result
106 -> { [FILE_IO ()] ==> [FILE_IO (if result
107 then OpenFile m
107 then OpenFile m
108− else ())] } Eff Bool
108+ else ())] } Eff e Bool
109open f m = call $ Open f m
109open f m = call $ Open f m
110
110
111
111
112||| Close a file.
112||| Close a file.
113−close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff ()
113+close : { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff e ()
114close = call $ Close
114close = call $ Close
115
115
116||| Read a line from the file.
116||| Read a line from the file.
117−readLine : { [FILE_IO (OpenFile Read)] } Eff String
117+readLine : { [FILE_IO (OpenFile Read)] } Eff e String
118readLine = call $ ReadLine
118readLine = call $ ReadLine
119
119
120||| Write a line to a file.
120||| Write a line to a file.
121−writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff ()
121+writeLine : String -> { [FILE_IO (OpenFile Write)] } Eff e ()
122writeLine str = call $ WriteLine str
122writeLine str = call $ WriteLine str
123
123
124||| End of file?
124||| End of file?
125−eof : { [FILE_IO (OpenFile Read)] } Eff Bool
125+eof : { [FILE_IO (OpenFile Read)] } Eff e Bool
126eof = call $ EOF
126eof = call $ EOF
127
127
128-- --------------------------------------------------------------------- [ EOF ]
128-- --------------------------------------------------------------------- [ EOF ]
libs/neweffects/Effect/Memory.idr → libs/oldeffects/Effect/Memory.idrrenamed+8−8
@@ -101,7 +101,7 @@ RAW_MEMORY : Type -> EFFECT
101RAW_MEMORY t = MkEff t RawMemory
101RAW_MEMORY t = MkEff t RawMemory
102
102
103allocate : (n : Nat) ->
103allocate : (n : Nat) ->
104− Eff () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
104+ Eff m () [RAW_MEMORY ()] (\v => [RAW_MEMORY (MemoryChunk n 0)])
105allocate size = call $ Allocate size
105allocate size = call $ Allocate size
106
106
107initialize : {i : Nat} ->
107initialize : {i : Nat} ->
@@ -109,18 +109,18 @@ initialize : {i : Nat} ->
109 Bits8 ->
109 Bits8 ->
110 (size : Nat) ->
110 (size : Nat) ->
111 so (i + size <= n) ->
111 so (i + size <= n) ->
112− Eff () [RAW_MEMORY (MemoryChunk n i)]
112+ Eff m () [RAW_MEMORY (MemoryChunk n i)]
113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
113 (\v => [RAW_MEMORY (MemoryChunk n (i + size))])
114initialize c size prf = call $ Initialize c size prf
114initialize c size prf = call $ Initialize c size prf
115
115
116−free : Eff () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
116+free : Eff m () [RAW_MEMORY (MemoryChunk n i)] (\v => [RAW_MEMORY ()])
117free = call Free
117free = call Free
118
118
119peek : {i : Nat} ->
119peek : {i : Nat} ->
120 (offset : Nat) ->
120 (offset : Nat) ->
121 (size : Nat) ->
121 (size : Nat) ->
122 so (offset + size <= i) ->
122 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)
124peek offset size prf = call $ Peek offset size prf
124peek offset size prf = call $ Peek offset size prf
125
125
126poke : {n : Nat} ->
126poke : {n : Nat} ->
@@ -128,12 +128,12 @@ poke : {n : Nat} ->
128 (offset : Nat) ->
128 (offset : Nat) ->
129 Vect size Bits8 ->
129 Vect size Bits8 ->
130 so (offset <= i && offset + size <= n) ->
130 so (offset <= i && offset + size <= n) ->
131− Eff () [RAW_MEMORY (MemoryChunk n i)]
131+ Eff m () [RAW_MEMORY (MemoryChunk n i)]
132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
132 (\v => [RAW_MEMORY (MemoryChunk n (max i (offset + size)))])
133poke offset content prf = call $ Poke offset content prf
133poke offset content prf = call $ Poke offset content prf
134
134
135private
135private
136−getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff (MemoryChunk n i)
136+getRawPtr : { [RAW_MEMORY (MemoryChunk n i)] } Eff m (MemoryChunk n i)
137getRawPtr = call $ GetRawPtr
137getRawPtr = call $ GetRawPtr
138
138
139private
139private
@@ -146,7 +146,7 @@ move' : {dst_size : Nat} ->
146 (size : Nat) ->
146 (size : Nat) ->
147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
147 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
148 so (src_offset + size <= src_init) ->
148 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)]
150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
150 (\v => [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))])
151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
151move' src_ptr dst_offset src_offset size dst_bounds src_bounds
152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
152 = call $ Move src_ptr dst_offset src_offset size dst_bounds src_bounds
@@ -162,7 +162,7 @@ move : {dst_size : Nat} ->
162 (size : Nat) ->
162 (size : Nat) ->
163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
163 so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
164 so (src_offset + size <= src_init) ->
164 so (src_offset + size <= src_init) ->
165− Eff ()
165+ Eff m ()
166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
166 [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
167 , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
168 (\v =>
168 (\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
17RND = MkEff Integer Random
17RND = MkEff Integer Random
18
18
19||| Generates a random Integer in a given range
19||| Generates a random Integer in a given range
20−rndInt : Integer -> Integer -> { [RND] } Eff Integer
20+rndInt : Integer -> Integer -> { [RND] } Eff m Integer
21rndInt lower upper = do v <- call $ getRandom
21rndInt lower upper = do v <- call $ getRandom
22 return (v `prim__sremBigInt` (upper - lower) + lower)
22 return (v `prim__sremBigInt` (upper - lower) + lower)
23
23
24||| Generate a random number in Fin (S `k`)
24||| Generate a random number in Fin (S `k`)
25|||
25|||
26||| Note that rndFin k takes values 0, 1, ..., k.
26||| 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))
28rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
28rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast (S k))
29 return (toFin v)
29 return (toFin v)
30 where toFin : Integer -> Fin (S k)
30 where toFin : Integer -> Fin (S k)
@@ -33,15 +33,15 @@ rndFin k = do let v = assert_total $ !(call getRandom) `prim__sremBigInt` (cast
33 Nothing => toFin (assert_smaller x (x - cast (S k)))
33 Nothing => toFin (assert_smaller x (x - cast (S k)))
34
34
35||| Select a random element from a vector
35||| 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
37rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
37rndSelect' {k} xs = return (Vect.index !(rndFin k) xs)
38
38
39||| Select a random element from a list, or Nothing if the list is empty
39||| 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)
41rndSelect [] = return Nothing
41rndSelect [] = return Nothing
42rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
42rndSelect (x::xs) = return (Just !(rndSelect' (x::(fromList xs))))
43
43
44||| Sets the random seed
44||| Sets the random seed
45−srand : Integer -> { [RND] } Eff ()
45+srand : Integer -> { [RND] } Eff m ()
46srand n = call $ setSeed n
46srand n = call $ setSeed n
47
47
libs/neweffects/Effect/Select.idr → libs/oldeffects/Effect/Select.idrrenamed+1−1
@@ -18,6 +18,6 @@ instance Handler Selection List where
18SELECT : EFFECT
18SELECT : EFFECT
19SELECT = MkEff () Selection
19SELECT = MkEff () Selection
20
20
21−select : List a -> { [SELECT] } Eff a
21+select : List a -> { [SELECT] } Eff m a
22select xs = call $ Select xs
22select xs = call $ Select xs
23
23
libs/neweffects/Effect/State.idr → libs/oldeffects/Effect/State.idrrenamed+8−8
@@ -8,30 +8,30 @@ data State : Effect where
8 Get : { a } State a
8 Get : { a } State a
9 Put : b -> { a ==> b } State ()
9 Put : b -> { a ==> b } State ()
10
10
11−-- using (m : Type -> Type)
11+using (m : Type -> Type)
12−instance Handler State m where
12+ instance Handler State m where
13 handle st Get k = k st st
13 handle st Get k = k st st
14 handle st (Put n) k = k () n
14 handle st (Put n) k = k () n
15
15
16STATE : Type -> EFFECT
16STATE : Type -> EFFECT
17STATE t = MkEff t State
17STATE t = MkEff t State
18
18
19−get : { [STATE x] } Eff x
19+get : { [STATE x] } Eff m x
20get = call $ Get
20get = call $ Get
21
21
22−put : x -> { [STATE x] } Eff ()
22+put : x -> { [STATE x] } Eff m ()
23put val = call $ Put val
23put val = call $ Put val
24
24
25−putM : y -> { [STATE x] ==> [STATE y] } Eff ()
25+putM : y -> { [STATE x] ==> [STATE y] } Eff m ()
26putM val = call $ Put val
26putM val = call $ Put val
27
27
28−update : (x -> x) -> { [STATE x] } Eff ()
28+update : (x -> x) -> { [STATE x] } Eff m ()
29update f = put (f !get)
29update f = put (f !get)
30
30
31−updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff ()
31+updateM : (x -> y) -> { [STATE x] ==> [STATE y] } Eff m ()
32updateM f = putM (f !get)
32updateM f = putM (f !get)
33
33
34−locally : x -> ({ [STATE x] } Eff t) -> { [STATE y] } Eff t
34+locally : x -> ({ [STATE x] } Eff m t) -> { [STATE y] } Eff m t
35locally newst prog = do st <- get
35locally newst prog = do st <- get
36 putM newst
36 putM newst
37 val <- prog
37 val <- prog
libs/neweffects/Effect/StdIO.idr → libs/oldeffects/Effect/StdIO.idrrenamed+5−5
@@ -39,22 +39,22 @@ STDIO : EFFECT
39STDIO = MkEff () StdIO
39STDIO = MkEff () StdIO
40
40
41||| Write a string to standard output.
41||| Write a string to standard output.
42−putStr : String -> { [STDIO] } Eff ()
42+putStr : String -> { [STDIO] } Eff e ()
43putStr s = call $ PutStr s
43putStr s = call $ PutStr s
44
44
45||| Write a character to standard output.
45||| Write a character to standard output.
46−putChar : Char -> { [STDIO] } Eff ()
46+putChar : Char -> { [STDIO] } Eff e ()
47putChar c = call $ PutCh c
47putChar c = call $ PutCh c
48
48
49||| Write a string to standard output, terminating with a newline.
49||| Write a string to standard output, terminating with a newline.
50−putStrLn : String -> { [STDIO] } Eff ()
50+putStrLn : String -> { [STDIO] } Eff e ()
51putStrLn s = putStr (s ++ "\n")
51putStrLn s = putStr (s ++ "\n")
52
52
53||| Read a string from standard input.
53||| Read a string from standard input.
54−getStr : { [STDIO] } Eff String
54+getStr : { [STDIO] } Eff e String
55getStr = call $ GetStr
55getStr = call $ GetStr
56
56
57||| Read a character from standard input.
57||| Read a character from standard input.
58−getChar : { [STDIO] } Eff Char
58+getChar : { [STDIO] } Eff e Char
59getChar = call $ GetCh
59getChar = call $ GetCh
60
60
libs/neweffects/Effect/System.idr → libs/oldeffects/Effect/System.idrrenamed+4−4
@@ -30,14 +30,14 @@ instance Handler System (IOExcept a) where
30SYSTEM : EFFECT
30SYSTEM : EFFECT
31SYSTEM = MkEff () System
31SYSTEM = MkEff () System
32
32
33−getArgs : { [SYSTEM] } Eff (List String)
33+getArgs : Handler System e => { [SYSTEM] } Eff e (List String)
34getArgs = call Args
34getArgs = call Args
35
35
36−time : { [SYSTEM] } Eff Int
36+time : Handler System e => { [SYSTEM] } Eff e Int
37time = call Time
37time = call Time
38
38
39−getEnv : String -> { [SYSTEM] } Eff (Maybe String)
39+getEnv : Handler System e => String -> { [SYSTEM] } Eff e (Maybe String)
40getEnv s = call $ GetEnv s
40getEnv s = call $ GetEnv s
41
41
42−system : String -> { [SYSTEM] } Eff Int
42+system : Handler System e => String -> { [SYSTEM] } Eff e Int
43system s = call $ CSystem s
43system s = call $ CSystem s
libs/neweffects/Effects.idr → libs/oldeffects/Effects.idrrenamed+102−59
@@ -10,7 +10,7 @@ import Effect.Default
10%access public
10%access public
11-- ----------------------------------------------------------------- [ Effects ]
11-- ----------------------------------------------------------------- [ Effects ]
12||| The Effect type describes effectful computations.
12||| The Effect type describes effectful computations.
13−|||
13+|||
14||| This type is parameterised by:
14||| This type is parameterised by:
15||| + The input resource.
15||| + The input resource.
16||| + The return type of the computation.
16||| + The return type of the computation.
@@ -28,11 +28,11 @@ data EFFECT : Type where
28||| underlying computation context `m` for execution.
28||| underlying computation context `m` for execution.
29class Handler (e : Effect) (m : Type -> Type) where
29class Handler (e : Effect) (m : Type -> Type) where
30 ||| How to handle the effect.
30 ||| How to handle the effect.
31− |||
31+ |||
32 ||| @ r The resource being handled.
32 ||| @ r The resource being handled.
33 ||| @ eff The effect to be applied.
33 ||| @ eff The effect to be applied.
34 ||| @ k The continuation to pass the result of the effect
34 ||| @ 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) ->
36 (k : ((x : t) -> resk x -> m a)) -> m a
36 (k : ((x : t) -> resk x -> m a)) -> m a
37
37
38||| Get the resource type (handy at the REPL to find out about an effect)
38||| Get the resource type (handy at the REPL to find out about an effect)
@@ -48,27 +48,28 @@ resourceType (MkEff t e) = t
48syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
48syntax "{" [inst] "}" [eff] = eff inst (\result => inst)
49
49
50-- The state transition is dependent on a result `b`, a bound variable.
50-- The state transition is dependent on a result `b`, a bound variable.
51−syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
51+syntax "{" [inst] "==>" "{" {b} "}" [outst] "}" [eff]
52 = eff inst (\b => outst)
52 = eff inst (\b => outst)
53
53
54--- A simple state transition
54--- A simple state transition
55syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
55syntax "{" [inst] "==>" [outst] "}" [eff] = eff inst (\result => outst)
56
56
57-- --------------------------------------- [ Properties and Proof Construction ]
57-- --------------------------------------- [ Properties and Proof Construction ]
58+using (xs : List a, ys : List a)
58−data SubList : List a -> List a -> Type where
59+ data SubList : List a -> List a -> Type where
59− SubNil : SubList [] []
60+ SubNil : SubList {a} [] []
60− Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
61+ Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
61− Drop : SubList xs ys -> SubList xs (x :: ys)
62+ Drop : SubList xs ys -> SubList xs (x :: ys)
62
63
63−subListId : SubList xs xs
64+ subListId : SubList xs xs
64−subListId {xs = Nil} = SubNil
65+ subListId {xs = Nil} = SubNil
65−subListId {xs = x :: xs} = Keep subListId
66+ subListId {xs = x :: xs} = Keep subListId
66
67
67namespace Env
68namespace Env
68 data Env : (m : Type -> Type) -> List EFFECT -> Type where
69 data Env : (m : Type -> Type) -> List EFFECT -> Type where
69 Nil : Env m Nil
70 Nil : Env m Nil
70 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
71 (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
71−
72+
72data EffElem : Effect -> Type ->
73data EffElem : Effect -> Type ->
73 List EFFECT -> Type where
74 List EFFECT -> Type where
74 Here : EffElem x a (MkEff a x :: xs)
75 Here : EffElem x a (MkEff a x :: xs)
@@ -128,62 +129,71 @@ relabel {xs = []} l [] = []
128relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
129relabel {xs = (MkEff a e :: xs)} l (v :: vs) = (l := v) :: relabel l vs
129
130
130-- ------------------------------------------------- [ The Language of Effects ]
131-- ------------------------------------------------- [ The Language of Effects ]
131−||| Definition of a language of effectful programs.
132+||| Definition of an Effect.
132−|||
133+|||
134+||| @ m The computation context
133||| @ x The return type of the result.
135||| @ x The return type of the result.
134||| @ es The list of allowed side-effects.
136||| @ es The list of allowed side-effects.
135||| @ ce Function to compute a new list of allowed side-effects.
137||| @ ce Function to compute a new list of allowed side-effects.
138+data Eff : (m : Type -> Type)
136−data Eff : (x : Type)
139+ -> (x : Type)
137 -> (es : List EFFECT)
140 -> (es : List EFFECT)
138 -> (ce : x -> List EFFECT) -> Type where
141 -> (ce : x -> List EFFECT) -> Type where
139− value : a -> Eff a xs (\v => xs)
142+ value : a -> Eff m a xs (\v => xs)
140− with_val : (val : a) -> Eff () xs (\v => xs' val) ->
143+ with_val : (val : a) -> Eff m () xs (\v => xs' val) ->
141− Eff a xs xs'
144+ Eff m a xs xs'
142− ebind : Eff a xs xs' ->
145+ ebind : Eff m a xs xs' ->
143− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
146+ ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
144 callP : (prf : EffElem e a xs) ->
147 callP : (prf : EffElem e a xs) ->
145 (eff : e t a b) ->
148 (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)
147
150
148 liftP : (prf : SubList ys xs) ->
151 liftP : (prf : SubList ys xs) ->
149− Eff t ys ys' -> Eff t xs (\v => updateWith (ys' v) xs prf)
152+ Eff m t ys ys' -> Eff m t xs (\v => updateWith (ys' v) xs prf)
150−
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+
151− (:-) : (l : ty) ->
161+ (:-) : (l : ty) ->
152− Eff t [x] xs' -> -- [x] (\v => xs) ->
162+ Eff m t [x] xs' -> -- [x] (\v => xs) ->
153− Eff t [l ::: x] (\v => map (l :::) (xs' v))
163+ Eff m t [l ::: x] (\v => map (l :::) (xs' v))
154−
164+
155−(>>=) : Eff a xs xs' ->
165+(>>=) : Eff m a xs xs' ->
156− ((val : a) -> Eff b (xs' val) xs'') -> Eff b xs xs''
166+ ((val : a) -> Eff m b (xs' val) xs'') -> Eff m b xs xs''
157−(>>=) = ebind
167+(>>=) = ebind
158
168
159-- namespace SimpleBind
169-- namespace SimpleBind
160−-- (>>=) : Eff m a xs (\v => xs) ->
170+-- (>>=) : Eff m a xs (\v => xs) ->
161-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
171-- ((val : a) -> Eff m b xs xs') -> Eff m b xs xs'
162−-- (>>=) = ebind
172+-- (>>=) = ebind
163
173
164||| Run a subprogram which results in an effect state the same as the input.
174||| 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)
166staticEff = id
176staticEff = id
167
177
168||| Explicitly give the expected set of result effects for an effectful
178||| Explicitly give the expected set of result effects for an effectful
169||| operation.
179||| 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')
171toEff xs' = id
181toEff xs' = id
172
182
173−return : a -> Eff a xs (\v => xs)
183+return : a -> Eff m a xs (\v => xs)
174return x = value x
184return x = value x
175
185
176-- ------------------------------------------------------ [ for idiom brackets ]
186-- ------------------------------------------------------ [ for idiom brackets ]
177
187
178infixl 2 <$>
188infixl 2 <$>
179
189
180−pure : a -> Eff a xs (\v => xs)
190+pure : a -> Eff m a xs (\v => xs)
181pure = value
191pure = value
182
192
183syntax pureM [val] = with_val val (pure ())
193syntax pureM [val] = with_val val (pure ())
184
194
185−(<$>) : Eff (a -> b) xs (\v => xs) ->
195+(<$>) : Eff m (a -> b) xs (\v => xs) ->
186− Eff a xs (\v => xs) -> Eff b xs (\v => xs)
196+ Eff m a xs (\v => xs) -> Eff m b xs (\v => xs)
187(<$>) prog v = do fn <- prog
197(<$>) prog v = do fn <- prog
188 arg <- v
198 arg <- v
189 return (fn arg)
199 return (fn arg)
@@ -203,15 +213,20 @@ execEff {e} {a} {res} {resk} (val :: env) (There p) eff k
203-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
213-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
204-- updates can be propagated even through failing computations?
214-- updates can be propagated even through failing computations?
205
215
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
207eff env (value x) k = k x env
217eff 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')
209eff env (prog `ebind` c) k
219eff env (prog `ebind` c) k
210 = eff env prog (\p', env' => eff env' (c p') k)
220 = eff env prog (\p', env' => eff env' (c p') k)
211eff env (callP prf effP) k = execEff env prf effP k
221eff env (callP prf effP) k = execEff env prf effP k
212eff env (liftP prf effP) k
222eff env (liftP prf effP) k
213 = let env' = dropEnv env prf in
223 = let env' = dropEnv env prf in
214 eff env' effP (\p', envk => k p' (rebuildEnv envk prf env))
224 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)
215-- FIXME:
230-- FIXME:
216-- xs is needed explicitly because otherwise the pattern binding for
231-- xs is needed explicitly because otherwise the pattern binding for
217-- 'l' appears too late. Solution seems to be to reorder patterns at the
232-- 'l' appears too late. Solution seems to be to reorder patterns at the
@@ -234,56 +249,84 @@ syntax MkDefaultEnv = with Env
234
249
235call : {a, b: _} -> {e : Effect} ->
250call : {a, b: _} -> {e : Effect} ->
236 (eff : e t a b) ->
251 (eff : e t a b) ->
237− {default tactics { search 100; }
238− prf : EffElem e a xs} ->
252+ {auto prf : EffElem e a xs} ->
239− Eff t xs (\v => updateResTy v xs prf eff)
253+ Eff m t xs (\v => updateResTy v xs prf eff)
240call e {prf} = callP prf e
254call e {prf} = callP prf e
241
255
242implicit
256implicit
243−lift : Eff t ys ys' ->
257+lift : Eff m t ys ys' ->
244− {default tactics { search 100; }
245− prf : SubList ys xs} ->
258+ {auto prf : SubList ys xs} ->
246− Eff t xs (\v => updateWith (ys' v) xs prf)
259+ Eff m t xs (\v => updateWith (ys' v) xs prf)
247lift e {prf} = liftP prf e
260lift e {prf} = liftP prf e
248
261
249
262
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+
250-- --------------------------------------------------------- [ Running Effects ]
269-- --------------------------------------------------------- [ Running Effects ]
251
270
252−||| Run an effectful program
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.
253−run : Applicative m => {default MkDefaultEnv env : Env m xs} -> Eff a xs xs' -> m a
277+run : Applicative m => {default MkDefaultEnv env : Env m xs} -> (prog : Eff m a xs xs') -> m a
254run {env} prog = eff env prog (\r, env => pure r)
278run {env} prog = eff env prog (\r, env => pure r)
255
279
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.
256−runPure : {default MkDefaultEnv env : Env id xs} -> Eff a xs xs' -> a
286+runPure : {default MkDefaultEnv env : Env id xs} -> (prog : Eff id a xs xs') -> a
257runPure {env} prog = eff env prog (\r, env => r)
287runPure {env} prog = eff env prog (\r, env => r)
258
288
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.
259−runInit : Applicative m => Env m xs -> Eff a xs xs' -> m a
295+runInit : Applicative m => (val : Env m xs) -> (prog : Eff m a xs xs') -> m a
260runInit env prog = eff env prog (\r, env => pure r)
296runInit env prog = eff env prog (\r, env => pure r)
261
297
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.
262−runPureInit : Env id xs -> Eff a xs xs' -> a
304+runPureInit : (val : Env id xs) -> (prog : Eff id a xs xs') -> a
263runPureInit env prog = eff env prog (\r, env => r)
305runPureInit env prog = eff env prog (\r, env => r)
264
306
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
266runWith inj env prog = eff env prog (\r, env => inj r)
308runWith inj env prog = eff env prog (\r, env => inj r)
267
309
268−runEnv : Applicative m => Env m xs -> Eff a xs xs' ->
310+runEnv : Applicative m => Env m xs -> Eff m a xs xs' ->
269 m (x : a ** Env m (xs' x))
311 m (x : a ** Env m (xs' x))
270runEnv env prog = eff env prog (\r, env => pure (r ** env))
312runEnv env prog = eff env prog (\r, env => pure (r ** env))
271
313
272-- ----------------------------------------------- [ some higher order things ]
314-- ----------------------------------------------- [ some higher order things ]
273
315
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)
275mapE f [] = pure []
317mapE f [] = pure []
276mapE f (x :: xs) = [| f x :: mapE f xs |]
318mapE f (x :: xs) = [| f x :: mapE f xs |]
277
319
278
320
321+mapVE : Applicative m =>
279−mapVE : (a -> {xs} Eff b) ->
322+ (a -> {xs} Eff m b) ->
280− Vect n a ->
323+ Vect n a ->
281− {xs} Eff (Vect n b)
324+ {xs} Eff m (Vect n b)
282mapVE f [] = pure []
325mapVE f [] = pure []
283mapVE f (x :: xs) = [| f x :: mapVE f xs |]
326mapVE f (x :: xs) = [| f x :: mapVE f xs |]
284
327
285
328
286−when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
329+when : Applicative m => Bool -> Lazy ({xs} Eff m ()) -> {xs} Eff m ()
287when True e = Force e
330when True e = Force e
288when False e = pure ()
331when False e = pure ()
289
332
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
2
2
3opts = "--nobasepkgs -i ../prelude -i ../base"
3opts = "--nobasepkgs -i ../prelude -i ../base"
4modules = Effects, Effect.Default,
4modules = Effects, Effect.Default,
test/effects001/test021.idr+1−1
@@ -9,7 +9,7 @@ data Count : Type where
9
9
10FileIO : Type -> Type -> Type
10FileIO : Type -> Type -> Type
11FileIO st t
11FileIO st t
12− = { [FILE_IO st, STDIO, Count ::: STATE Int] } Eff IO t
12+ = { [FILE_IO st, STDIO, Count ::: STATE Int] } Eff t
13
13
14readFile : FileIO (OpenFile Read) (List String)
14readFile : FileIO (OpenFile Read) (List String)
15readFile = readAcc [] where
15readFile = readAcc [] where
test/effects001/test021a.idr+1−1
@@ -17,7 +17,7 @@ Env = List (String, Integer)
17-- Evaluator t
17-- Evaluator t
18-- = Eff m [EXCEPTION String, RND, STATE Env] t
18-- = Eff m [EXCEPTION String, RND, STATE Env] t
19
19
20−eval : Expr -> { [EXCEPTION String, STDIO, RND, STATE Env] } Eff IO Integer
20+eval : Expr -> { [EXCEPTION String, STDIO, RND, STATE Env] } Eff Integer
21eval (Var x) = do vs <- get
21eval (Var x) = do vs <- get
22 case lookup x vs of
22 case lookup x vs of
23 Nothing => raise ("No such variable " ++ x)
23 Nothing => raise ("No such variable " ++ x)
test/effects002/test025.idr+1−1
@@ -6,7 +6,7 @@ import Control.IOExcept
6
6
7MemoryIO : Type -> Type -> Type -> Type
7MemoryIO : Type -> Type -> Type -> Type
8MemoryIO td ts r = { [ Dst ::: RAW_MEMORY td
8MemoryIO td ts r = { [ Dst ::: RAW_MEMORY td
9− , Src ::: RAW_MEMORY ts ] } Eff (IOExcept String) r
9+ , Src ::: RAW_MEMORY ts ] } Eff r
10
10
11inpVect : Vect 5 Bits8
11inpVect : Vect 5 Bits8
12inpVect = map prim__truncInt_B8 [0, 1, 2, 3, 5]
12inpVect = map prim__truncInt_B8 [0, 1, 2, 3, 5]