Skip to content

Commit 94b8465

Browse files
committed
Merge pull request #31 from pseudonom/patch-2
Added `monadErrorMaybe` instance
2 parents 47bfe3f + d02b728 commit 94b8465

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Control/Monad/Error/Class.purs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ import Control.Monad.Reader.Trans
88
import Control.Monad.Writer.Trans
99
import Control.Monad.State.Trans
1010
import Data.Either
11+
import Data.Maybe
1112
import Data.Monoid
1213

1314
class MonadError e m where
1415
throwError :: forall a. e -> m a
1516
catchError :: forall a. m a -> (e -> m a) -> m a
1617

17-
instance monadErrorError :: MonadError e (Either e) where
18+
instance monadErrorEither :: MonadError e (Either e) where
1819
throwError = Left
1920
catchError (Left e) h = h e
2021
catchError (Right x) _ = Right x
2122

23+
instance monadErrorMaybe :: MonadError Unit Maybe where
24+
throwError = const Nothing
25+
catchError Nothing f = f unit
26+
catchError (Just a) _ = Just a
27+
2228
instance monadErrorErrorT :: (Monad m) => MonadError e (ErrorT e m) where
2329
throwError e = ErrorT $ return (Left e)
2430
catchError m h = ErrorT $ do

0 commit comments

Comments
 (0)