[ base ] Implement MonadError () for MaybeT

This commit is contained in:
Denis Buzdalov 2022-08-31 19:20:54 +03:00 committed by G. Allais
parent 6891490ed2
commit 5266a2bc22

View File

@ -74,6 +74,11 @@ MonadError () Maybe where
catchError Nothing f = f ()
catchError x _ = x
public export
Monad m => MonadError () (MaybeT m) where
throwError () = MkMaybeT $ pure Nothing
catchError (MkMaybeT m) f = MkMaybeT $ m >>= maybe (runMaybeT $ f ()) (pure @{Compose})
public export
MonadError e (Either e) where
throwError = Left