@@ -2,25 +2,28 @@ module Control.IOExcept
3-- An IO monad with exception handling
3-- An IO monad with exception handling
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)
9−instance Functor (IOExcept e) where
9+instance 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)
12−instance Applicative (IOExcept e) where
12+instance 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 |]
16−instance Monad (IOExcept e) where
16+instance 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)
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
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)
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
28+IOExcept : Type -> Type -> Type
29+IOExcept = IOExcept' FFI_C