| Copyright | (C) 2008-2014 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | provisional |
| Portability | MPTCs |
| Safe Haskell | Trustworthy |
| Language | Haskell98 |
Control.Monad.Trans.Either
Description
This module provides a minimalist Either monad transformer.
- newtype EitherT e m a = EitherT {
- runEitherT :: m (Either e a)
- eitherT :: Monad m => (a -> m c) -> (b -> m c) -> EitherT a m b -> m c
- bimapEitherT :: Functor m => (e -> f) -> (a -> b) -> EitherT e m a -> EitherT f m b
- mapEitherT :: (m (Either e a) -> n (Either e' b)) -> EitherT e m a -> EitherT e' n b
- hoistEither :: Monad m => Either e a -> EitherT e m a
- bracketEitherT :: Monad m => EitherT e m a -> (a -> EitherT e m b) -> (a -> EitherT e m c) -> EitherT e m c
- bracketEitherT_ :: Monad m => EitherT e m a -> EitherT e m b -> EitherT e m c -> EitherT e m c
- left :: Monad m => e -> EitherT e m a
- right :: Monad m => a -> EitherT e m a
- swapEitherT :: Functor m => EitherT e m a -> EitherT a m e
Documentation
EitherT is a version of ErrorT that does not
require a spurious Error instance for the Left
case.
Either is a perfectly usable Monad without such a constraint. ErrorT is
not the generalization of the current Either monad, it is something else.
This is necessary for both theoretical and practical reasons. For instance an
apomorphism is the generalized anamorphism for this Monad, but it cannot be
written with ErrorT.
In addition to the combinators here, the errors package provides a large
number of combinators for working with this type.
Constructors
| EitherT | |
Fields
| |
Instances
eitherT :: Monad m => (a -> m c) -> (b -> m c) -> EitherT a m b -> m c Source
Given a pair of actions, one to perform in case of failure, and one to perform
in case of success, run an EitherT and get back a monadic result.
bimapEitherT :: Functor m => (e -> f) -> (a -> b) -> EitherT e m a -> EitherT f m b Source
Map over both failure and success.
mapEitherT :: (m (Either e a) -> n (Either e' b)) -> EitherT e m a -> EitherT e' n b Source
Map the unwrapped computation using the given function.
runEitherT(mapEitherTf m) = f (runEitherTm)
bracketEitherT :: Monad m => EitherT e m a -> (a -> EitherT e m b) -> (a -> EitherT e m c) -> EitherT e m c Source
bracketEitherT_ :: Monad m => EitherT e m a -> EitherT e m b -> EitherT e m c -> EitherT e m c Source
Version of bracketEitherT which discards the result from the initial
action.
swapEitherT :: Functor m => EitherT e m a -> EitherT a m e Source
Monad transformer version of swapEither.