Module

Control.Monad.Except.Trans

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the exception monad transformer ExceptT.

#ExceptT Source

newtype ExceptT :: Type -> (Type -> Type) -> Type -> Typenewtype ExceptT e m a

A monad transformer which adds exceptions to other monads, in the same way as Except. As before, e is the type of exceptions, and a is the type of successful results. The new type parameter m is the inner monad that computations run in.

Constructors

Instances

#runExceptT Source

runExceptT :: forall e m a. ExceptT e m a -> m (Either e a)

The inverse of ExceptT. Run a computation in the ExceptT monad.

#withExceptT Source

withExceptT :: forall e e' m a. Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a

Transform any exceptions thrown by an ExceptT computation using the given function.

#mapExceptT Source

mapExceptT :: forall e e' m n a b. (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b

Transform the unwrapped computation using the given function.

#except Source

except :: forall e m a. Applicative m => Either e a -> ExceptT e m a

Construct a computation in the ExceptT transformer from an Either value.

Re-exports from Control.Monad.Error.Class

#MonadError Source

class MonadError :: Type -> (Type -> Type) -> Constraintclass (MonadThrow e m) <= MonadError e m | m -> e where

The MonadError type class represents those monads which support catching errors.

  • catchError x f calls the error handler f if an error is thrown during the evaluation of x.

An implementation is provided for ExceptT, and for other monad transformers defined in this library.

Laws:

  • Catch: catchError (throwError e) f = f e
  • Pure: catchError (pure a) f = pure a

Members

Instances

#MonadThrow Source

class MonadThrow :: Type -> (Type -> Type) -> Constraintclass (Monad m) <= MonadThrow e m | m -> e where

The MonadThrow type class represents those monads which support errors via throwError, where throwError e halts, yielding the error e.

An implementation is provided for ExceptT, and for other monad transformers defined in this library.

Laws:

  • Left zero: throwError e >>= f = throwError e

Members

Instances

Re-exports from Control.Monad.Trans.Class

#MonadTrans Source

class MonadTrans :: ((Type -> Type) -> Type -> Type) -> Constraintclass MonadTrans t  where

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.

Laws:

  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }

Members