Module

Data.EitherR

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

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

Constructors

Instances

#runEitherR

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

#succeed

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

Complete error handling, returning a result

#throwEither

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

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

#catchEither

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

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

#handleEither

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

catchEither with the arguments flipped

#fmapL

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

Map a function over the Left value of an Either

#flipEither

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

Flip the type variables of Either

#ExceptRT

newtype ExceptRT r m e

EitherR converted into a monad transformer

Constructors

Instances

#runExceptRT

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

#succeedT

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

Complete error handling, returning a result

#fmapLT

fmapLT :: forall e e' m r. 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

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

Modules