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