Data.EitherR
- Package
- purescript-errors
- Repository
- passy/purescript-errors
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
isthrowEither
.(>>=)
iscatchEither
.Successful results abort the computation
Constructors
Instances
#runEitherR Source
runEitherR :: forall r e. EitherR r e -> Either e r
#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
#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
Constructors
Instances
(Monad m) => Functor (ExceptRT r m)
(Monad m) => Apply (ExceptRT r m)
(Monad m) => Applicative (ExceptRT r m)
(Monad m) => Bind (ExceptRT r m)
(Monad m) => Monad (ExceptRT r m)
(Monoid r, Monad m) => Alt (ExceptRT r m)
(Monoid r, Monad m) => Plus (ExceptRT r m)
(Monoid r, Monad m) => Alternative (ExceptRT r m)
(Monoid r, Monad m) => MonadZero (ExceptRT r m)
(Monoid r, Monad m) => MonadPlus (ExceptRT r m)
MonadTrans (ExceptRT r)
(MonadEffect m) => MonadEffect (ExceptRT r m)
#runExceptRT Source
runExceptRT :: forall r m e. ExceptRT r m e -> ExceptT e m r
- Modules
- Control.
Error. Util - Data.
EitherR