on master help sign in
Turn IOException into a record to avoid the let-binding patmatch.

Write the monad instance in terms of that projection + either instead of casing on the Either. Using ! instead of >>= (which I thought should be equivalent) results in a funky internal error.

commit80d88b1e227e8939b48fba3243f4db0137fec08d authorLeif Warner <abimelech@gmail.com> dateFri 30 Oct 2015, 01:06 (11 years ago) parent076c2d6
1 file changed+4−7
libs/base/Control/IOExcept.idr+4−7
libs/base/Control/IOExcept.idr+4−7
@@ -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