HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleerrors-2.3.0Haskell98

Data.EitherR

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.

  • 2 types
  • 10 values
  • Packageerrors-2.3.0
  • Exports12
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceEitherR.hs

EitherR

1 declaration
newtypenewtype EitherR r e
#

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

Constructors

Instances5Monad, Functor, Applicative, Alternative, MonadPlus

Operations in the EitherR monad

valuesucceed :: r -> EitherR r e
#

Complete error handling, returning a result

Conversions to the Either monad

Flip alternative

ExceptRT

1 declaration
newtypenewtype ExceptRT r (m :: Type -> Type) e
#

EitherR converted into a monad transformer

Constructors

Instances7MonadTrans, Monad, Functor, Applicative, Alternative, MonadPlus, …

Operations in the ExceptRT monad

Conversions to the ExceptT monad

Flip alternative