@@ -2,25 +2,28 @@ module Control.IOExcept
22
33-- An IO monad with exception handling
44
5−record IOExcept err a where
5+record IOExcept' (f:FFI) err a where
66 constructor IOM
7− runIOExcept : IO (Either err a)
7+ runIOExcept : IO' f (Either err a)
88
9−implementation Functor (IOExcept e) where
9+Functor (IOExcept' f e) where
1010 map f (IOM fn) = IOM (map (map f) fn)
1111
12−implementation Applicative (IOExcept e) where
12+Applicative (IOExcept' f e) where
1313 pure x = IOM (pure (pure x))
1414 (IOM f) <*> (IOM a) = IOM [| f <*> a |]
1515
16−implementation Monad (IOExcept e) where
16+Monad (IOExcept' f e) where
1717 (IOM x) >>= f = IOM $ x >>= either (pure . Left) (runIOExcept . f)
1818
19−ioe_lift : IO a -> IOExcept err a
19+ioe_lift : IO' f a -> IOExcept' f err a
2020ioe_lift op = IOM $ map Right op
2121
22−ioe_fail : err -> IOExcept err a
22+ioe_fail : err -> IOExcept' f err a
2323ioe_fail e = IOM $ pure (Left e)
2424
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
2626ioe_run (IOM act) err ok = either err ok !act
27+
28+IOExcept : Type -> Type -> Type
29+IOExcept = IOExcept' FFI_C