on master help sign in
Merge branch 'ioexcept-ffi' of https://github.com/aaronc/Idris-dev into aaronc-ioexcept-ffi
9b2ca04Edwin Brady
CONTRIBUTORS+1
@@ -11,6 +11,7 @@ Jakob Brünker
11Alyssa Carter
11Alyssa Carter
12David Raymond Christiansen
12David Raymond Christiansen
13Carter Charbonneau
13Carter Charbonneau
14+Aaron Craelius
14Jason Dagit
15Jason Dagit
15Guglielmo Fachini
16Guglielmo Fachini
16Simon Fowler
17Simon Fowler
libs/base/Control/IOExcept.idr+11−8
@@ -2,25 +2,28 @@ module Control.IOExcept
2
2
3-- An IO monad with exception handling
3-- An IO monad with exception handling
4
4
5−record IOExcept err a where
5+record IOExcept' (f:FFI) err a where
6 constructor IOM
6 constructor IOM
7− runIOExcept : IO (Either err a)
7+ runIOExcept : IO' f (Either err a)
8
8
9−implementation Functor (IOExcept e) where
9+Functor (IOExcept' f e) where
10 map f (IOM fn) = IOM (map (map f) fn)
10 map f (IOM fn) = IOM (map (map f) fn)
11
11
12−implementation Applicative (IOExcept e) where
12+Applicative (IOExcept' f e) where
13 pure x = IOM (pure (pure x))
13 pure x = IOM (pure (pure x))
14 (IOM f) <*> (IOM a) = IOM [| f <*> a |]
14 (IOM f) <*> (IOM a) = IOM [| f <*> a |]
15
15
16−implementation Monad (IOExcept e) where
16+Monad (IOExcept' f e) where
17 (IOM x) >>= f = IOM $ x >>= either (pure . Left) (runIOExcept . f)
17 (IOM x) >>= f = IOM $ x >>= either (pure . Left) (runIOExcept . f)
18
18
19−ioe_lift : IO a -> IOExcept err a
19+ioe_lift : IO' f a -> IOExcept' f err a
20ioe_lift op = IOM $ map Right op
20ioe_lift op = IOM $ map Right op
21
21
22−ioe_fail : err -> IOExcept err a
22+ioe_fail : err -> IOExcept' f err a
23ioe_fail e = IOM $ pure (Left e)
23ioe_fail e = IOM $ pure (Left e)
24
24
25−ioe_run : IOExcept err a -> (err -> IO b) -> (a -> IO b) -> IO b
25+ioe_run : IOExcept' f err a -> (err -> IO' f b) -> (a -> IO' f b) -> IO' f b
26ioe_run (IOM act) err ok = either err ok !act
26ioe_run (IOM act) err ok = either err ok !act
27+
28+IOExcept : Type -> Type -> Type
29+IOExcept = IOExcept' FFI_C