This module provides throwEither and cachEither for Either. These functions reside here because throwEither and catchEither correspond to return and bind for flipped Either monad: EitherR.

catchEither differs from MonadError (cacheError) - catchEither is more general as it allows you to change the left value's type.

throwEither is just throwError but exists here for consistency.

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.

#EitherR Source

newtype EitherR r e

If Either e r is the error monad, then EitherR r e is the corresponding success monad, where:

  • return is throwEither.

  • (>>=) is catchEither.

  • Successful results abort the computation



#runEitherR Source

runEitherR :: forall r e. EitherR r e -> Either e r

#succeed Source

succeed :: forall r e. r -> EitherR r e

Complete error handling, returning a result

#throwEither Source

throwEither :: forall r e. e -> Either e r

throwEither in the error monad corresponds to return in the success monad

#catchEither Source

catchEither :: forall r e' e. Either e r -> (e -> Either e' r) -> Either e' r

catchEither in the error monad corresponds to (>>=) in the success monad

#handleEither Source

handleEither :: forall r e' e. (e -> Either e' r) -> Either e r -> Either e' r

catchEither with the arguments flipped

#fmapL Source

fmapL :: forall r e' e. (e -> e') -> Either e r -> Either e' r

Map a function over the Left value of an Either

#flipEither Source

flipEither :: forall b a. Either a b -> Either b a

Flip the type variables of Either

#ExceptRT Source

newtype ExceptRT r m e

EitherR converted into a monad transformer



#runExceptRT Source

runExceptRT :: forall r m e. ExceptRT r m e -> ExceptT e m r

#succeedT Source

succeedT :: forall r m e. Monad m => r -> ExceptRT r m e

Complete error handling, returning a result

#fmapLT Source

fmapLT :: forall r m e' e. Monad m => (e -> e') -> ExceptT e m r -> ExceptT e' m r

Modify ExceptT error value The same as Control.Monad.Except.Trans.withExceptT, but left here for module API consistency.

#flipET Source

flipET :: forall r m a. Monad m => ExceptT a m r -> ExceptT r m a