@@ -2,8 +2,9 @@ module Control.IOExcept
3-- An IO monad with exception handling
3-- An IO monad with exception handling
5−data IOExcept : Type -> Type -> Type where
5+record IOExcept err a where
6− IOM : IO (Either err a) -> IOExcept err a
7+ runIOExcept : IO (Either err a)
8instance Functor (IOExcept e) where
9instance Functor (IOExcept e) where
9 map f (IOM fn) = IOM (map (map f) fn)
10 map f (IOM fn) = IOM (map (map f) fn)
@@ -13,11 +14,7 @@ instance Applicative (IOExcept e) where
13 (IOM f) <*> (IOM a) = IOM [| f <*> a |]
14 (IOM f) <*> (IOM a) = IOM [| f <*> a |]
15instance Monad (IOExcept e) where
16instance Monad (IOExcept e) where
16− (IOM x) >>= k = IOM (do x' <- x;
17+ (IOM x) >>= f = IOM $ x >>= either (pure . Left) (runIOExcept . f)
18− Right a => let (IOM ka) = k a in
20− Left err => return (Left err))
22ioe_lift : IO a -> IOExcept err a
19ioe_lift : IO a -> IOExcept err a
23ioe_lift op = IOM $ map Right op
20ioe_lift op = IOM $ map Right op