on master help sign in
Remove oldeffects

(I forgot I hadn't done this already... but there's surely nobody still using it!)

commitf9fe15385a0ee79bf36b8d9795f9c41d7f052886 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 14 Jun 2014, 18:07 (12 years ago) parentfec66de
11 files changed−784
libs/oldeffects/Effect/Exception.idr−40 libs/oldeffects/Effect/File.idr−69 libs/oldeffects/Effect/Memory.idr−169 libs/oldeffects/Effect/Monad.idr−21 libs/oldeffects/Effect/Random.idr−25 libs/oldeffects/Effect/Select.idr−23 libs/oldeffects/Effect/State.idr−40 libs/oldeffects/Effect/StdIO.idr−60 libs/oldeffects/Effects.idr−308 libs/oldeffects/Makefile−21 libs/oldeffects/oldeffects.ipkg−8
libs/oldeffects/Effect/Exception.idrdeleted−40
@@ -1,40 +0,0 @@
1−module Effect.Exception
2−
3−import Effects
4−import System
5−import Control.IOExcept
6−
7−data Exception : Type -> Type -> Type -> Type -> Type where
8− Raise : a -> Exception a () () b
9−
10−instance Handler (Exception a) Maybe where
11− handle _ (Raise e) k = Nothing
12−
13−instance Show a => Handler (Exception a) IO where
14− handle _ (Raise e) k = do print e
15− believe_me (exit 1)
16−
17−instance Handler (Exception a) (IOExcept a) where
18− handle _ (Raise e) k = ioM (return (Left e))
19−
20−instance Handler (Exception a) (Either a) where
21− handle _ (Raise e) k = Left e
22−
23−EXCEPTION : Type -> EFFECT
24−EXCEPTION t = MkEff () (Exception t)
25−
26−raise : a -> Eff m [EXCEPTION a] b
27−raise err = Raise err
28−
29−
30−
31−
32−
33−
34−
35−-- TODO: Catching exceptions mid program?
36−-- probably need to invoke a new interpreter
37−
38−-- possibly add a 'handle' to the Eff language so that an alternative
39−-- handler can be introduced mid interpretation?
40−
libs/oldeffects/Effect/File.idrdeleted−69
@@ -1,69 +0,0 @@
1−module Effect.File
2−
3−import Effects
4−import Control.IOExcept
5−
6−data OpenFile : Mode -> Type where
7− FH : File -> OpenFile m
8−
9−data FileIO : Effect where
10− Open : String -> (m : Mode) -> FileIO () (Either () (OpenFile m)) Bool
11− Close : FileIO (OpenFile m) () ()
12−
13− ReadLine : FileIO (OpenFile Read) (OpenFile Read) String
14− WriteLine : String -> FileIO (OpenFile Write) (OpenFile Write) ()
15− EOF : FileIO (OpenFile Read) (OpenFile Read) Bool
16−
17−
18−instance Handler FileIO IO where
19− handle () (Open fname m) k = do h <- openFile fname m
20− valid <- validFile h
21− if valid then k (Right (FH h)) True
22− else k (Left ()) False
23− handle (FH h) Close k = do closeFile h
24− k () ()
25− handle (FH h) ReadLine k = do str <- fread h
26− k (FH h) str
27− handle (FH h) (WriteLine str) k = do fwrite h str
28− k (FH h) ()
29− handle (FH h) EOF k = do e <- feof h
30− k (FH h) e
31−
32−instance Handler FileIO (IOExcept String) where
33− handle () (Open fname m) k
34− = do h <- ioe_lift (openFile fname m)
35− valid <- ioe_lift (validFile h)
36− if valid then k (Right (FH h)) True
37− else k (Left ()) False
38− handle (FH h) Close k = do ioe_lift (closeFile h); k () ()
39− handle (FH h) ReadLine k = do str <- ioe_lift (fread h)
40− k (FH h) str
41− handle (FH h) (WriteLine str) k = do ioe_lift (fwrite h str)
42− k (FH h) ()
43− handle (FH h) EOF k = do e <- ioe_lift (feof h)
44− k (FH h) e
45−
46−FILE_IO : Type -> EFFECT
47−FILE_IO t = MkEff t FileIO
48−
49−open : Handler FileIO e =>
50− String -> (m : Mode) -> EffM e [FILE_IO ()]
51− [FILE_IO (Either () (OpenFile m))] Bool
52−open f m = Open f m
53−
54−close : Handler FileIO e =>
55− EffM e [FILE_IO (OpenFile m)] [FILE_IO ()] ()
56−close = Close
57−
58−readLine : Handler FileIO e => Eff e [FILE_IO (OpenFile Read)] String
59−readLine = ReadLine
60−
61−writeLine : Handler FileIO e => String -> Eff e [FILE_IO (OpenFile Write)] ()
62−writeLine str = WriteLine str
63−
64−eof : Handler FileIO e => Eff e [FILE_IO (OpenFile Read)] Bool
65−eof = EOF
66−
67−
68−
69−
libs/oldeffects/Effect/Memory.idrdeleted−169
@@ -1,169 +0,0 @@
1−module Effect.Memory
2−
3−import Effects
4−import Control.IOExcept
5−
6−%access public
7−
8−abstract
9−data MemoryChunk : Nat -> Nat -> Type where
10− CH : Ptr -> MemoryChunk size initialized
11−
12−abstract
13−data RawMemory : Effect where
14− Allocate : (n : Nat) ->
15− RawMemory () (MemoryChunk n 0) ()
16− Free : RawMemory (MemoryChunk n i) () ()
17− Initialize : Bits8 ->
18− (size : Nat) ->
19− so (i + size <= n) ->
20− RawMemory (MemoryChunk n i) (MemoryChunk n (i + size)) ()
21− Peek : (offset : Nat) ->
22− (size : Nat) ->
23− so (offset + size <= i) ->
24− RawMemory (MemoryChunk n i) (MemoryChunk n i) (Vect size Bits8)
25− Poke : (offset : Nat) ->
26− (Vect size Bits8) ->
27− so (offset <= i && offset + size <= n) ->
28− RawMemory (MemoryChunk n i) (MemoryChunk n (max i (offset + size))) ()
29− Move : (src : MemoryChunk src_size src_init) ->
30− (dst_offset : Nat) ->
31− (src_offset : Nat) ->
32− (size : Nat) ->
33− so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
34− so (src_offset + size <= src_init) ->
35− RawMemory (MemoryChunk dst_size dst_init)
36− (MemoryChunk dst_size (max dst_init (dst_offset + size))) ()
37− GetRawPtr : RawMemory (MemoryChunk n i) (MemoryChunk n i) (MemoryChunk n i)
38−
39−private
40−do_malloc : Nat -> IOExcept String Ptr
41−do_malloc size with (fromInteger (cast size) == size)
42− | True = do ptr <- ioe_lift $ mkForeign (FFun "malloc" [FInt] FPtr) (fromInteger $ cast size)
43− fail <- ioe_lift $ nullPtr ptr
44− if fail then ioe_fail "Cannot allocate memory"
45− else return ptr
46− | False = ioe_fail "The target architecture does not support adressing enough memory"
47−
48−private
49−do_memset : Ptr -> Nat -> Bits8 -> Nat -> IO ()
50−do_memset ptr offset c size
51− = mkForeign (FFun "idris_memset" [FPtr, FInt, FByte, FInt] FUnit)
52− ptr (fromInteger $ cast offset) c (fromInteger $ cast size)
53−
54−private
55−do_free : Ptr -> IO ()
56−do_free ptr = mkForeign (FFun "free" [FPtr] FUnit) ptr
57−
58−private
59−do_memmove : Ptr -> Ptr -> Nat -> Nat -> Nat -> IO ()
60−do_memmove dest src dest_offset src_offset size
61− = mkForeign (FFun "idris_memmove" [FPtr, FPtr, FInt, FInt, FInt] FUnit)
62− dest src (fromInteger $ cast dest_offset) (fromInteger $ cast src_offset) (fromInteger $ cast size)
63−
64−private
65−do_peek : Ptr -> Nat -> (size : Nat) -> IO (Vect size Bits8)
66−do_peek _ _ Z = return (Prelude.Vect.Nil)
67−do_peek ptr offset (S n)
68− = do b <- mkForeign (FFun "idris_peek" [FPtr, FInt] FByte) ptr (fromInteger $ cast offset)
69− bs <- do_peek ptr (S offset) n
70− Prelude.Monad.return (Prelude.Vect.(::) b bs)
71−
72−private
73−do_poke : Ptr -> Nat -> Vect size Bits8 -> IO ()
74−do_poke _ _ [] = return ()
75−do_poke ptr offset (b::bs)
76− = do mkForeign (FFun "idris_poke" [FPtr, FInt, FByte] FUnit) ptr (fromInteger $ cast offset) b
77− do_poke ptr (S offset) bs
78−
79−instance Handler RawMemory (IOExcept String) where
80− handle () (Allocate n) k
81− = do ptr <- do_malloc n
82− k (CH ptr) ()
83− handle (CH ptr) (Initialize {i} c size _) k
84− = ioe_lift (do_memset ptr i c size) $> k (CH ptr) ()
85− handle (CH ptr) (Free) k
86− = ioe_lift (do_free ptr) $> k () ()
87− handle (CH ptr) (Peek offset size _) k
88− = do res <- ioe_lift (do_peek ptr offset size)
89− k (CH ptr) res
90− handle (CH ptr) (Poke offset content _) k
91− = do ioe_lift (do_poke ptr offset content)
92− k (CH ptr) ()
93− handle (CH dest_ptr) (Move (CH src_ptr) dest_offset src_offset size _ _) k
94− = do ioe_lift (do_memmove dest_ptr src_ptr dest_offset src_offset size)
95− k (CH dest_ptr) ()
96− handle chunk (GetRawPtr) k
97− = k chunk chunk
98−
99−RAW_MEMORY : Type -> EFFECT
100−RAW_MEMORY t = MkEff t RawMemory
101−
102−allocate : (n : Nat) -> EffM m [RAW_MEMORY ()] [RAW_MEMORY (MemoryChunk n 0)] ()
103−allocate size = Allocate size
104−
105−initialize : {i : Nat} ->
106− {n : Nat} ->
107− Bits8 ->
108− (size : Nat) ->
109− so (i + size <= n) ->
110− EffM m [RAW_MEMORY (MemoryChunk n i)] [RAW_MEMORY (MemoryChunk n (i + size))] ()
111−initialize c size prf = Initialize c size prf
112−
113−free : EffM m [RAW_MEMORY (MemoryChunk n i)] [RAW_MEMORY ()] ()
114−free = Free
115−
116−peek : {i : Nat} ->
117− (offset : Nat) ->
118− (size : Nat) ->
119− so (offset + size <= i) ->
120− Eff m [RAW_MEMORY (MemoryChunk n i)] (Vect size Bits8)
121−peek offset size prf = Peek offset size prf
122−
123−poke : {n : Nat} ->
124− {i : Nat} ->
125− (offset : Nat) ->
126− Vect size Bits8 ->
127− so (offset <= i && offset + size <= n) ->
128− EffM m [RAW_MEMORY (MemoryChunk n i)] [RAW_MEMORY (MemoryChunk n (max i (offset + size)))] ()
129−poke offset content prf = Poke offset content prf
130−
131−private
132−getRawPtr : Eff m [RAW_MEMORY (MemoryChunk n i)] (MemoryChunk n i)
133−getRawPtr = GetRawPtr
134−
135−private
136−move' : {dst_size : Nat} ->
137− {dst_init : Nat} ->
138− {src_init : Nat} ->
139− (src_ptr : MemoryChunk src_size src_init) ->
140− (dst_offset : Nat) ->
141− (src_offset : Nat) ->
142− (size : Nat) ->
143− so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
144− so (src_offset + size <= src_init) ->
145− EffM m [RAW_MEMORY (MemoryChunk dst_size dst_init)]
146− [RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))] ()
147−move' src_ptr dst_offset src_offset size dst_bounds src_bounds
148− = Move src_ptr dst_offset src_offset size dst_bounds src_bounds
149−
150−data MoveDescriptor = Dst | Src
151−
152−move : {dst_size : Nat} ->
153− {dst_init : Nat} ->
154− {src_size : Nat} ->
155− {src_init : Nat} ->
156− (dst_offset : Nat) ->
157− (src_offset : Nat) ->
158− (size : Nat) ->
159− so (dst_offset <= dst_init && dst_offset + size <= dst_size) ->
160− so (src_offset + size <= src_init) ->
161− EffM m [ Dst ::: RAW_MEMORY (MemoryChunk dst_size dst_init)
162− , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)]
163− [ Dst ::: RAW_MEMORY (MemoryChunk dst_size (max dst_init (dst_offset + size)))
164− , Src ::: RAW_MEMORY (MemoryChunk src_size src_init)] ()
165−move dst_offset src_offset size dst_bounds src_bounds
166− = do src_ptr <- Src :- getRawPtr
167− Dst :- move' src_ptr dst_offset src_offset size dst_bounds src_bounds
168− return ()
169−
libs/oldeffects/Effect/Monad.idrdeleted−21
@@ -1,21 +0,0 @@
1−module Effect.Monad
2−
3−import Effects
4−
5−-- Eff is a monad too, so we can happily use it in a monad transformer.
6−
7−using (xs : List EFFECT, m : Type -> Type)
8− instance Functor (EffM m xs xs) where
9− map f prog = do t <- prog
10− value (f t)
11−
12− instance Applicative (EffM m xs xs) where
13− pure = value
14− (<$>) f a = do f' <- f
15− a' <- a
16− value (f' a')
17−
18− instance Monad (EffM m xs xs) where
19− (>>=) = ebind
20−
21−
libs/oldeffects/Effect/Random.idrdeleted−25
@@ -1,25 +0,0 @@
1−module Effect.Random
2−
3−import Effects
4−
5−data Random : Type -> Type -> Type -> Type where
6− getRandom : Random Integer Integer Integer
7− setSeed : Integer -> Random Integer Integer ()
8−
9−using (m : Type -> Type)
10− instance Handler Random m where
11− handle seed getRandom k
12− = let seed' = (1664525 * seed + 1013904223) `prim__sremBigInt` (pow 2 32) in
13− k seed' seed'
14− handle seed (setSeed n) k = k n ()
15−
16−RND : EFFECT
17−RND = MkEff Integer Random
18−
19−rndInt : Integer -> Integer -> Eff m [RND] Integer
20−rndInt lower upper = do v <- getRandom
21− return (v `prim__sremBigInt` (upper - lower) + lower)
22−
23−srand : Integer -> Eff m [RND] ()
24−srand n = setSeed n
25−
libs/oldeffects/Effect/Select.idrdeleted−23
@@ -1,23 +0,0 @@
1−module Effect.Select
2−
3−import Effects
4−
5−data Selection : Effect where
6− Select : List a -> Selection () () a
7−
8−instance Handler Selection Maybe where
9− handle _ (Select xs) k = tryAll xs where
10− tryAll [] = Nothing
11− tryAll (x :: xs) = case k () x of
12− Nothing => tryAll xs
13− Just v => Just v
14−
15−instance Handler Selection List where
16− handle r (Select xs) k = concatMap (k r) xs
17−
18−SELECT : EFFECT
19−SELECT = MkEff () Selection
20−
21−select : List a -> Eff m [SELECT] a
22−select xs = Select xs
23−
libs/oldeffects/Effect/State.idrdeleted−40
@@ -1,40 +0,0 @@
1−module Effect.State
2−
3−import Effects
4−
5−%access public
6−
7−data State : Effect where
8− Get : State a a a
9− Put : b -> State a b ()
10−
11−using (m : Type -> Type)
12− instance Handler State m where
13− handle st Get k = k st st
14− handle st (Put n) k = k n ()
15−
16−STATE : Type -> EFFECT
17−STATE t = MkEff t State
18−
19−get : Eff m [STATE x] x
20−get = Get
21−
22−put : x -> Eff m [STATE x] ()
23−put val = Put val
24−
25−putM : y -> EffM m [STATE x] [STATE y] ()
26−putM val = Put val
27−
28−update : (x -> x) -> Eff m [STATE x] ()
29−update f = put (f !get)
30−
31−updateM : (x -> y) -> EffM m [STATE x] [STATE y] ()
32−updateM f = putM (f !get)
33−
34−locally : x -> Eff m [STATE x] t -> Eff m [STATE y] t
35−locally newst prog = do st <- get
36− putM newst
37− val <- prog
38− putM st
39− return val
40−
libs/oldeffects/Effect/StdIO.idrdeleted−60
@@ -1,60 +0,0 @@
1−module Effect.StdIO
2−
3−import Effects
4−import Control.IOExcept
5−
6−data StdIO : Effect where
7− PutStr : String -> StdIO () () ()
8− GetStr : StdIO () () String
9−
10−instance Handler StdIO IO where
11− handle () (PutStr s) k = do putStr s; k () ()
12− handle () GetStr k = do x <- getLine; k () x
13−
14−instance Handler StdIO (IOExcept a) where
15− handle () (PutStr s) k = do ioe_lift (putStr s); k () ()
16− handle () GetStr k = do x <- ioe_lift getLine; k () x
17−
18−-- Handle effects in a pure way, for simulating IO for unit testing/proof
19−
20−data IOStream a = MkStream (List String -> (a, List String))
21−
22−instance Handler StdIO IOStream where
23− handle () (PutStr s) k
24− = MkStream (\x => case k () () of
25− MkStream f => let (res, str) = f x in
26− (res, s :: str))
27− handle {a} () GetStr k
28− = MkStream (\x => case x of
29− [] => cont "" []
30− (t :: ts) => cont t ts)
31− where
32− cont : String -> List String -> (a, List String)
33− cont t ts = case k () t of
34− MkStream f => f ts
35−
36−--- The Effect and associated functions
37−
38−STDIO : EFFECT
39−STDIO = MkEff () StdIO
40−
41−putStr : Handler StdIO e => String -> Eff e [STDIO] ()
42−putStr s = PutStr s
43−
44−putStrLn : Handler StdIO e => String -> Eff e [STDIO] ()
45−putStrLn s = putStr (s ++ "\n")
46−
47−getStr : Handler StdIO e => Eff e [STDIO] String
48−getStr = GetStr
49−
50−mkStrFn : Env IOStream xs ->
51− Eff IOStream xs a ->
52− List String -> (a, List String)
53−mkStrFn {a} env p input = case mkStrFn' of
54− MkStream f => f input
55− where injStream : a -> IOStream a
56− injStream v = MkStream (\x => (v, []))
57− mkStrFn' : IOStream a
58− mkStrFn' = runWith injStream env p
59−
60−
libs/oldeffects/Effects.idrdeleted−308
@@ -1,308 +0,0 @@
1−module Effects
2−
3−import Language.Reflection
4−import Control.Catchable
5−
6−%access public
7−
8−---- Effects
9−
10−Effect : Type
11−Effect = Type -> Type -> Type -> Type
12−
13−%error_reverse
14−data EFFECT : Type where
15− MkEff : Type -> Effect -> EFFECT
16−
17−class Handler (e : Effect) (m : Type -> Type) where
18− handle : res -> (eff : e res res' t) -> (res' -> t -> m a) -> m a
19−
20−---- Properties and proof construction
21−
22−using (xs : List a, ys : List a)
23− data SubList : List a -> List a -> Type where
24− SubNil : SubList {a} [] []
25− Keep : SubList xs ys -> SubList (x :: xs) (x :: ys)
26− Drop : SubList xs ys -> SubList xs (x :: ys)
27−
28− subListId : SubList xs xs
29− subListId {xs = Nil} = SubNil
30− subListId {xs = x :: xs} = Keep subListId
31−
32−data Env : (m : Type -> Type) -> List EFFECT -> Type where
33− Nil : Env m Nil
34− (::) : Handler eff m => a -> Env m xs -> Env m (MkEff a eff :: xs)
35−
36−data EffElem : (Type -> Type -> Type -> Type) -> Type ->
37− List EFFECT -> Type where
38− Here : EffElem x a (MkEff a x :: xs)
39− There : EffElem x a xs -> EffElem x a (y :: xs)
40−
41−-- make an environment corresponding to a sub-list
42−dropEnv : Env m ys -> SubList xs ys -> Env m xs
43−dropEnv [] SubNil = []
44−dropEnv (v :: vs) (Keep rest) = v :: dropEnv vs rest
45−dropEnv (v :: vs) (Drop rest) = dropEnv vs rest
46−
47−updateWith : (ys' : List a) -> (xs : List a) ->
48− SubList ys xs -> List a
49−updateWith (y :: ys) (x :: xs) (Keep rest) = y :: updateWith ys xs rest
50−updateWith ys (x :: xs) (Drop rest) = x :: updateWith ys xs rest
51−updateWith [] [] SubNil = []
52−updateWith (y :: ys) [] SubNil = y :: ys
53−updateWith [] (x :: xs) (Keep rest) = []
54−
55−-- put things back, replacing old with new in the sub-environment
56−rebuildEnv : Env m ys' -> (prf : SubList ys xs) ->
57− Env m xs -> Env m (updateWith ys' xs prf)
58−rebuildEnv [] SubNil env = env
59−rebuildEnv (x :: xs) (Keep rest) (y :: env) = x :: rebuildEnv xs rest env
60−rebuildEnv xs (Drop rest) (y :: env) = y :: rebuildEnv xs rest env
61−rebuildEnv (x :: xs) SubNil [] = x :: xs
62−
63−---- The Effect EDSL itself ----
64−
65−-- some proof automation
66−
67−%reflection
68−reflectListEffElem : List a -> Tactic
69−reflectListEffElem [] = Refine "Here" `Seq` Solve
70−reflectListEffElem (x :: xs)
71− = Try (Refine "Here" `Seq` Solve)
72− (Refine "There" `Seq` (Solve `Seq` reflectListEffElem xs))
73−-- TMP HACK! FIXME!
74−-- The evaluator needs a 'function case' to know its a reflection function
75−-- until we propagate that information! Without this, the _ case won't get
76−-- matched.
77−reflectListEffElem (x ++ y) = Refine "Here" `Seq` Solve
78−reflectListEffElem _ = Refine "Here" `Seq` Solve
79−
80−%reflection
81−reflectSubList : List a -> Tactic
82−reflectSubList [] = Refine "SubNil" `Seq` Solve
83−reflectSubList (x :: xs)
84− = Try (Refine "subListId" `Seq` Solve)
85− (Try (Refine "Keep" `Seq` (Solve `Seq` reflectSubList xs))
86− (Refine "Drop" `Seq` (Solve `Seq` reflectSubList xs)))
87−reflectSubList (x ++ y) = Refine "subListId" `Seq` Solve
88−reflectSubList _ = Refine "subListId" `Seq` Solve
89−
90−%reflection
91−reflectEff : (P : Type) -> Tactic
92−reflectEff (EffElem m a xs)
93− = reflectListEffElem xs `Seq` Solve
94−reflectEff (SubList xs ys)
95− = reflectSubList ys `Seq` Solve
96−
97−updateResTy : (xs : List EFFECT) -> EffElem e a xs -> e a b t ->
98− List EFFECT
99−updateResTy {b} (MkEff a e :: xs) Here n = (MkEff b e) :: xs
100−updateResTy (x :: xs) (There p) n = x :: updateResTy xs p n
101−
102−updateResTyImm : (xs : List EFFECT) -> EffElem e a xs -> Type ->
103− List EFFECT
104−updateResTyImm (MkEff a e :: xs) Here b = (MkEff b e) :: xs
105−updateResTyImm (x :: xs) (There p) b = x :: updateResTyImm xs p b
106−
107−infix 5 :::, :-, :=
108−
109−data LRes : lbl -> Type -> Type where
110− (:=) : (x : lbl) -> res -> LRes x res
111−
112−(:::) : lbl -> EFFECT -> EFFECT
113−(:::) {lbl} x (MkEff r eff) = MkEff (LRes x r) eff
114−
115−private
116−unlabel : {l : ty} -> Env m [l ::: x] -> Env m [x]
117−unlabel {m} {x = MkEff a eff} [l := v] = [v]
118−
119−private
120−relabel : (l : ty) -> Env m [x] -> Env m [l ::: x]
121−relabel {x = MkEff a eff} l [v] = [l := v]
122−
123−-- the language of Effects
124−
125−data EffM : (m : Type -> Type) ->
126− List EFFECT -> List EFFECT -> Type -> Type where
127− value : a -> EffM m xs xs a
128− ebind : EffM m xs xs' a -> (a -> EffM m xs' xs'' b) -> EffM m xs xs'' b
129− effect : (prf : EffElem e a xs) ->
130− (eff : e a b t) ->
131− EffM m xs (updateResTy xs prf eff) t
132− lift : (prf : SubList ys xs) ->
133− EffM m ys ys' t -> EffM m xs (updateWith ys' xs prf) t
134− new : Handler e m =>
135− res -> EffM m (MkEff res e :: xs) (MkEff res' e :: xs') a ->
136− EffM m xs xs' a
137− test : (prf : EffElem e (Either l r) xs) ->
138− EffM m (updateResTyImm xs prf l) xs' t ->
139− EffM m (updateResTyImm xs prf r) xs' t ->
140− EffM m xs xs' t
141− test_lbl : {x : lbl} ->
142− (prf : EffElem e (LRes x (Either l r)) xs) ->
143− EffM m (updateResTyImm xs prf (LRes x l)) xs' t ->
144− EffM m (updateResTyImm xs prf (LRes x r)) xs' t ->
145− EffM m xs xs' t
146− catch : Catchable m err =>
147− EffM m xs xs' a -> (err -> EffM m xs xs' a) ->
148− EffM m xs xs' a
149− (:-) : (l : ty) -> EffM m [x] [y] t -> EffM m [l ::: x] [l ::: y] t
150−
151−syntax [tag] ":!" [val] = !(tag :- val)
152−
153−-- Eff : List (EFFECT m) -> Type -> Type
154−
155−-- For making proofs implicitly for 'test' and 'test_lbl'
156−
157−syntax if_valid then [e] else [t] =
158− test (tactics { byReflection reflectEff; }) t e
159−
160−syntax if_valid [lbl] then [e] else [t] =
161− test_lbl {x=lbl} (tactics { byReflection reflectEff; }) t e
162−
163−syntax if_error then [t] else [e] =
164− test (tactics { byReflection reflectEff; }) t e
165−
166−syntax if_error [lbl] then [t] else [e] =
167− test_lbl {x=lbl} (tactics { byReflection reflectEff; }) t e
168−
169−-- These may read better in some contexts
170−
171−syntax if_right then [e] else [t] =
172− test (tactics { byReflection reflectEff; }) t e
173−
174−syntax if_right [lbl] then [e] else [t] =
175− test_lbl {x=lbl} (tactics { byReflection reflectEff; }) t e
176−
177−syntax if_left then [t] else [e] =
178− test (tactics { byReflection reflectEff; }) t e
179−
180−syntax if_left [lbl] then [t] else [e] =
181− test_lbl {x=lbl} (tactics { byReflection reflectEff; }) t e
182−
183−
184−-- for 'do' notation
185−
186−return : a -> EffM m xs xs a
187−return x = value x
188−
189−(>>=) : EffM m xs xs' a -> (a -> EffM m xs' xs'' b) -> EffM m xs xs'' b
190−(>>=) = ebind
191−
192−-- for idiom brackets
193−
194−infixl 2 <$>
195−
196−pure : a -> EffM m xs xs a
197−pure = value
198−
199−(<$>) : EffM m xs xs (a -> b) -> EffM m xs xs a -> EffM m xs xs b
200−(<$>) prog v = do fn <- prog
201− arg <- v
202− return (fn arg)
203−
204−-- an interpreter
205−
206−private
207−execEff : Env m xs -> (p : EffElem e res xs) ->
208− (eff : e res b a) ->
209− (Env m (updateResTy xs p eff) -> a -> m t) -> m t
210−execEff (val :: env) Here eff' k
211− = handle val eff' (\res, v => k (res :: env) v)
212−execEff {e} {res} {b} {a} (val :: env) (There p) eff k
213− = execEff {e} {res} {b} {a} env p eff (\env', v => k (val :: env') v)
214−
215−private
216−testEff : Env m xs -> (p : EffElem e (Either l r) xs) ->
217− (Env m (updateResTyImm xs p l) -> m b) ->
218− (Env m (updateResTyImm xs p r) -> m b) ->
219− m b
220−testEff (Left err :: env) Here lk rk = lk (err :: env)
221−testEff (Right ok :: env) Here lk rk = rk (ok :: env)
222−testEff (val :: env) (There p) lk rk
223− = testEff env p (\envk => lk (val :: envk))
224− (\envk => rk (val :: envk))
225−
226−private
227−testEffLbl : {x : lblTy} ->
228− Env m xs -> (p : EffElem e (LRes x (Either l r)) xs) ->
229− (Env m (updateResTyImm xs p (LRes x l)) -> m b) ->
230− (Env m (updateResTyImm xs p (LRes x r)) -> m b) ->
231− m b
232−testEffLbl ((lbl := Left err) :: env) Here lk rk = lk ((lbl := err) :: env)
233−testEffLbl ((lbl := Right ok) :: env) Here lk rk = rk ((lbl := ok) :: env)
234−testEffLbl (val :: env) (There p) lk rk
235− = testEffLbl env p (\envk => lk (val :: envk))
236− (\envk => rk (val :: envk))
237−
238−-- Q: Instead of m b, implement as StateT (Env m xs') m b, so that state
239−-- updates can be propagated even through failing computations?
240−
241−eff : Env m xs -> EffM m xs xs' a -> (Env m xs' -> a -> m b) -> m b
242−eff env (value x) k = k env x
243−eff env (prog `ebind` c) k
244− = eff env prog (\env', p' => eff env' (c p') k)
245−eff env (effect prf effP) k = execEff env prf effP k
246−eff env (lift prf effP) k
247− = let env' = dropEnv env prf in
248− eff env' effP (\envk, p' => k (rebuildEnv envk prf env) p')
249−eff env (new r prog) k
250− = eff (r :: env) prog (\(v :: envk), p' => k envk p')
251−eff env (test prf l r) k
252− = testEff env prf (\envk => eff envk l k) (\envk => eff envk r k)
253−eff env (test_lbl prf l r) k
254− = testEffLbl env prf (\envk => eff envk l k) (\envk => eff envk r k)
255−eff env (catch prog handler) k
256− = catch (eff env prog k)
257− (\e => eff env (handler e) k)
258−-- FIXME:
259−-- xs is needed explicitly because otherwise the pattern binding for
260−-- 'l' appears too late. Solution seems to be to reorder patterns at the
261−-- end so that everything is in scope when it needs to be.
262−eff {xs = [l ::: x]} env (l :- prog) k
263− = let env' = unlabel env in
264− eff env' prog (\envk, p' => k (relabel l envk) p')
265−
266−implicit
267−lift' : EffM m ys ys' t ->
268− {default tactics { byReflection reflectEff; }
269− prf : SubList ys xs} ->
270− EffM m xs (updateWith ys' xs prf) t
271−lift' e {prf} = lift prf e
272−
273−implicit
274−effect' : {a, b: _} -> {e : Effect} ->
275− (eff : e a b t) ->
276− {default tactics { byReflection reflectEff; }
277− prf : EffElem e a xs} ->
278− EffM m xs (updateResTy xs prf eff) t
279−effect' e {prf} = effect prf e
280−
281−
282−run : Applicative m => Env m xs -> EffM m xs xs' a -> m a
283−run env prog = eff env prog (\env, r => pure r)
284−
285−runEnv : Applicative m => Env m xs -> EffM m xs xs' a -> m (Env m xs', a)
286−runEnv env prog = eff env prog (\env, r => pure (env, r))
287−
288−runPure : Env id xs -> EffM id xs xs' a -> a
289−runPure env prog = eff env prog (\env, r => r)
290−
291−-- runPureEnv : Env id xs -> EffM id xs xs' a -> (Env id xs', a)
292−-- runPureEnv env prog = eff env prog (\env, r => (env, r))
293−
294−runWith : (a -> m a) -> Env m xs -> EffM m xs xs' a -> m a
295−runWith inj env prog = eff env prog (\env, r => inj r)
296−
297−Eff : (Type -> Type) -> List EFFECT -> Type -> Type
298−Eff m xs t = EffM m xs xs t
299−
300−-- some higher order things
301−
302−mapE : Applicative m => (a -> Eff m xs b) -> List a -> Eff m xs (List b)
303−mapE f [] = pure []
304−mapE f (x :: xs) = [| f x :: mapE f xs |]
305−
306−when : Applicative m => Bool -> Lazy (Eff m xs ()) -> Eff m xs ()
307−when True e = e
308−when False e = pure ()
libs/oldeffects/Makefiledeleted−21
@@ -1,21 +0,0 @@
1−IDRIS := idris
2−PKG := oldeffects
3−
4−build:
5− $(IDRIS) --build ${PKG}.ipkg
6−
7−clean:
8− $(IDRIS) --clean ${PKG}.ipkg
9−
10−install:
11− $(IDRIS) --install ${PKG}.ipkg
12−
13−rebuild: clean build
14−
15−doc:
16− $(IDRIS) --mkdoc ${PKG}.ipkg
17−
18−doc_clean:
19− rm -rf ${PKG}_doc
20−
21−.PHONY: build clean install rebuild doc
libs/oldeffects/oldeffects.ipkgdeleted−8
@@ -1,8 +0,0 @@
1−package oldeffects
2−
3−opts = "--nobasepkgs -i ../prelude -i ../base"
4−modules = Effects,
5− Effect.Exception, Effect.File, Effect.State,
6− Effect.Random, Effect.StdIO, Effect.Select,
7− Effect.Memory, Effect.Monad
8−