either-4.4.1.1: An either monad transformer

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.

Synopsis

- 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

newtype EitherT e m a Source #

`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

- runEitherT :: m (Either e a)

Instances

(Functor f, MonadFree f m) => MonadFree f (EitherT e m) Source # |
Methods wrap :: f (EitherT e m a) -> EitherT e m a #
MonadBase b m => MonadBase b (EitherT e m) Source # |
Methods liftBase :: b α -> EitherT e m α #
MonadBaseControl b m => MonadBaseControl b (EitherT e m) Source # |
Associated Types type StM (EitherT e m :: * -> *) a :: * # Methods liftBaseWith :: (RunInBase (EitherT e m) b -> b a) -> EitherT e m a # restoreM :: StM (EitherT e m) a -> EitherT e m a #
Monad m => MonadError e (EitherT e m) Source # |
Methods throwError :: e -> EitherT e m a # catchError :: EitherT e m a -> (e -> EitherT e m a) -> EitherT e m a #
MonadReader r m => MonadReader r (EitherT e m) Source # |
Methods ask :: EitherT e m r # local :: (r -> r) -> EitherT e m a -> EitherT e m a # reader :: (r -> a) -> EitherT e m a #
MonadState s m => MonadState s (EitherT e m) Source # |
Methods get :: EitherT e m s # put :: s -> EitherT e m () # state :: (s -> (a, s)) -> EitherT e m a #
MonadWriter s m => MonadWriter s (EitherT e m) Source # |
Methods writer :: (a, s) -> EitherT e m a # tell :: s -> EitherT e m () # listen :: EitherT e m a -> EitherT e m (a, s) # pass :: EitherT e m (a, s -> s) -> EitherT e m a #
MonadTrans (EitherT e) Source # |
Methods lift :: Monad m => m a -> EitherT e m a #
MFunctor (EitherT e) Source # |
Methods hoist :: Monad m => (forall a. m a -> n a) -> EitherT e m b -> EitherT e n b #
MonadTransControl (EitherT e) Source # |
Associated Types type StT (EitherT e :: (* -> *) -> * -> *) a :: * # Methods liftWith :: Monad m => (Run (EitherT e) -> m a) -> EitherT e m a # restoreT :: Monad m => m (StT (EitherT e) a) -> EitherT e m a #
Monad m => Monad (EitherT e m) Source # |
Methods (>>=) :: EitherT e m a -> (a -> EitherT e m b) -> EitherT e m b # (>>) :: EitherT e m a -> EitherT e m b -> EitherT e m b # return :: a -> EitherT e m a # fail :: String -> EitherT e m a #
Monad m => Functor (EitherT e m) Source # |
Methods fmap :: (a -> b) -> EitherT e m a -> EitherT e m b # (<$) :: a -> EitherT e m b -> EitherT e m a #
MonadFix m => MonadFix (EitherT e m) Source # |
Methods mfix :: (a -> EitherT e m a) -> EitherT e m a #
Monad m => Applicative (EitherT e m) Source # |
Methods pure :: a -> EitherT e m a # (<*>) :: EitherT e m (a -> b) -> EitherT e m a -> EitherT e m b # (*>) :: EitherT e m a -> EitherT e m b -> EitherT e m b # (<*) :: EitherT e m a -> EitherT e m b -> EitherT e m a #
Foldable m => Foldable (EitherT e m) Source # |

Methods

fold :: Monoid m => EitherT e m m -> m #

foldMap :: Monoid m => (a -> m) -> EitherT e m a -> m #

foldr :: (a -> b -> b) -> b -> EitherT e m a -> b #

foldr' :: (a -> b -> b) -> b -> EitherT e m a -> b #

foldl :: (b -> a -> b) -> b -> EitherT e m a -> b #

foldl' :: (b -> a -> b) -> b -> EitherT e m a -> b #

foldr1 :: (a -> a -> a) -> EitherT e m a -> a #

foldl1 :: (a -> a -> a) -> EitherT e m a -> a #

toList :: EitherT e m a -> [a] #

null :: EitherT e m a -> Bool #

length :: EitherT e m a -> Int #

elem :: Eq a => a -> EitherT e m a -> Bool #

maximum :: Ord a => EitherT e m a -> a #

minimum :: Ord a => EitherT e m a -> a #

sum :: Num a => EitherT e m a -> a #

product :: Num a => EitherT e m a -> a #

(Monad f, Traversable f) => Traversable (EitherT e f) Source # |
Methods traverse :: Applicative f => (a -> f b) -> EitherT e f a -> f (EitherT e f b) # sequenceA :: Applicative f => EitherT e f (f a) -> f (EitherT e f a) # mapM :: Monad m => (a -> m b) -> EitherT e f a -> m (EitherT e f b) # sequence :: Monad m => EitherT e f (m a) -> m (EitherT e f a) #
(Monad m, Monoid e) => MonadPlus (EitherT e m) Source # |
Methods mzero :: EitherT e m a # mplus :: EitherT e m a -> EitherT e m a -> EitherT e m a #
MonadIO m => MonadIO (EitherT e m) Source # |
Methods liftIO :: IO a -> EitherT e m a #
MonadRandom m => MonadRandom (EitherT e m) Source # |
Methods getRandomR :: Random a => (a, a) -> EitherT e m a # getRandom :: Random a => EitherT e m a # getRandomRs :: Random a => (a, a) -> EitherT e m [a] # getRandoms :: Random a => EitherT e m [a] #
(Monad m, Monoid e) => Alternative (EitherT e m) Source # |
Methods empty :: EitherT e m a # (<|>) :: EitherT e m a -> EitherT e m a -> EitherT e m a # some :: EitherT e m a -> EitherT e m [a] # many :: EitherT e m a -> EitherT e m [a] #
MonadThrow m => MonadThrow (EitherT e m) Source # | Throws exceptions into the base monad.
Methods throwM :: Exception e => e -> EitherT e m a #
MonadCatch m => MonadCatch (EitherT e m) Source # | Catches exceptions from the base monad.
Methods catch :: Exception e => EitherT e m a -> (e -> EitherT e m a) -> EitherT e m a #
MonadCont m => MonadCont (EitherT e m) Source # |
Methods callCC :: ((a -> EitherT e m b) -> EitherT e m a) -> EitherT e m a #
(Monad m, Semigroup e) => Alt (EitherT e m) Source # |
Methods (<!>) :: EitherT e m a -> EitherT e m a -> EitherT e m a # some :: Applicative (EitherT e m) => EitherT e m a -> EitherT e m [a] # many :: Applicative (EitherT e m) => EitherT e m a -> EitherT e m [a] #
Monad m => Apply (EitherT e m) Source # |
Methods (<.>) :: EitherT e m (a -> b) -> EitherT e m a -> EitherT e m b # (.>) :: EitherT e m a -> EitherT e m b -> EitherT e m b # (<.) :: EitherT e m a -> EitherT e m b -> EitherT e m a #
Monad m => Bind (EitherT e m) Source # |
Methods (>>-) :: EitherT e m a -> (a -> EitherT e m b) -> EitherT e m b # join :: EitherT e m (EitherT e m a) -> EitherT e m a #
Eq (m (Either e a)) => Eq (EitherT e m a) Source # |
Methods (==) :: EitherT e m a -> EitherT e m a -> Bool # (/=) :: EitherT e m a -> EitherT e m a -> Bool #
Ord (m (Either e a)) => Ord (EitherT e m a) Source # |
Methods compare :: EitherT e m a -> EitherT e m a -> Ordering # (<) :: EitherT e m a -> EitherT e m a -> Bool # (<=) :: EitherT e m a -> EitherT e m a -> Bool # (>) :: EitherT e m a -> EitherT e m a -> Bool # (>=) :: EitherT e m a -> EitherT e m a -> Bool # max :: EitherT e m a -> EitherT e m a -> EitherT e m a # min :: EitherT e m a -> EitherT e m a -> EitherT e m a #
Read (m (Either e a)) => Read (EitherT e m a) Source # |
Methods readsPrec :: Int -> ReadS (EitherT e m a) # readList :: ReadS [EitherT e m a] # readPrec :: ReadPrec (EitherT e m a) # readListPrec :: ReadPrec [EitherT e m a] #
Show (m (Either e a)) => Show (EitherT e m a) Source # |
Methods showsPrec :: Int -> EitherT e m a -> ShowS # show :: EitherT e m a -> String # showList :: [EitherT e m a] -> ShowS #
Monad m => Semigroup (EitherT e m a) Source # |
Methods (<>) :: EitherT e m a -> EitherT e m a -> EitherT e m a # sconcat :: NonEmpty (EitherT e m a) -> EitherT e m a # stimes :: Integral b => b -> EitherT e m a -> EitherT e m a #
type StT (EitherT e) a Source # |
type StT (EitherT e) a = Either e a
type StM (EitherT e m) a Source # |
type StM (EitherT e m) a = StM m (StT (EitherT e) a)

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 (mapEitherT f m) = f (runEitherT m)

hoistEither :: Monad m => Either e a -> EitherT e m a Source #

Lift an `Either` into an `EitherT`

bracketEitherT :: Monad m => EitherT e m a -> (a -> EitherT e m b) -> (a -> EitherT e m c) -> EitherT e m c Source #

Acquire a resource in `EitherT` and then perform an action with it, cleaning up afterwards regardless of error. Like `bracket`, but acting only in `EitherT`.

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.

left :: Monad m => e -> EitherT e m a Source #

Analogous to `Left`. Equivalent to `throwError`.

right :: Monad m => a -> EitherT e m a Source #

Analogous to `Right`. Equivalent to `return`.

swapEitherT :: Functor m => EitherT e m a -> EitherT a m e Source #

Monad transformer version of `swapEither`.