This module provides
throwEither and
catchEither for
Either. These two functions reside here because
throwEither and
catchEither correspond to
return
and (
>>=) for the flipped
Either monad:
EitherR. Additionally, this module defines
handleE as
the flipped version of
catchE for
ExceptT.
throwEither and
catchEither improve upon
MonadError because:
- catchEither is more general than catch and allows
you to change the left value's type
- Both are Haskell98
More advanced users can use
EitherR and
ExceptRT to
program in an entirely symmetric "success monad" where exceptional
results are the norm and successful results terminate the computation.
This allows you to chain error-handlers using
do notation and
pass around exceptional values of varying types until you can finally
recover from the error:
runExceptRT $ do
e2 <- ioExceptionHandler e1
bool <- arithmeticExceptionhandler e2
when bool $ lift $ putStrLn "DEBUG: Arithmetic handler did something"
If any of the above error handlers
succeed, no other handlers
are tried.
If you choose not to typefully distinguish between the error and
sucess monad, then use
flipEither and
flipET, which swap
the type variables without changing the type.