transformers-0.3.0.0: Concrete functor and monad transformers

Portability | portable
Stability | experimental
Maintainer | ross@soi.city.ac.uk
Safe Haskell | Safe-Inferred

Control.Monad.Trans.Maybe

Contents

- The MaybeT monad transformer
- Lifting other operations

Description

The `MaybeT` monad transformer adds the ability to fail to a monad.

A sequence of actions succeeds, producing a value, only if all the actions in the sequence are successful. If one fails, the rest of the sequence is skipped and the composite action fails.

For a variant allowing a range of error values, see Control.Monad.Trans.Error.

Synopsis

- newtype MaybeT m a = MaybeT {
  - runMaybeT :: m (Maybe a)
  }
- mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
- liftCallCC :: (((Maybe a -> m (Maybe b)) -> m (Maybe a)) -> m (Maybe a)) -> ((a -> MaybeT m b) -> MaybeT m a) -> MaybeT m a
- liftCatch :: (m (Maybe a) -> (e -> m (Maybe a)) -> m (Maybe a)) -> MaybeT m a -> (e -> MaybeT m a) -> MaybeT m a
- liftListen :: Monad m => (m (Maybe a) -> m (Maybe a, w)) -> MaybeT m a -> MaybeT m (a, w)
- liftPass :: Monad m => (m (Maybe a, w -> w) -> m (Maybe a)) -> MaybeT m (a, w -> w) -> MaybeT m a

# The MaybeT monad transformer

newtype MaybeT m a Source

The parameterizable maybe monad, obtained by composing an arbitrary monad with the `Maybe` monad.

Computations are actions that may produce a value or fail.

The `return` function yields a successful computation, while `>>=` sequences two subcomputations, failing on the first error.

Constructors

MaybeT |
Fields runMaybeT :: m (Maybe a)

Instances

MonadTrans MaybeT |
Monad m => Monad (MaybeT m) |
Functor m => Functor (MaybeT m) |
MonadFix m => MonadFix (MaybeT m) |
Monad m => MonadPlus (MaybeT m) |
(Functor m, Monad m) => Applicative (MaybeT m) |
Foldable f => Foldable (MaybeT f) |
Traversable f => Traversable (MaybeT f) |
(Functor m, Monad m) => Alternative (MaybeT m) |
MonadIO m => MonadIO (MaybeT m) |

mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n bSource

Transform the computation inside a `MaybeT`.

-     runMaybeT (mapMaybeT f m) = f (runMaybeT m)

# Lifting other operations

liftCallCC :: (((Maybe a -> m (Maybe b)) -> m (Maybe a)) -> m (Maybe a)) -> ((a -> MaybeT m b) -> MaybeT m a) -> MaybeT m aSource

Lift a `callCC` operation to the new monad.

liftCatch :: (m (Maybe a) -> (e -> m (Maybe a)) -> m (Maybe a)) -> MaybeT m a -> (e -> MaybeT m a) -> MaybeT m aSource

Lift a `catchError` operation to the new monad.

liftListen :: Monad m => (m (Maybe a) -> m (Maybe a, w)) -> MaybeT m a -> MaybeT m (a, w)Source

Lift a `listen` operation to the new monad.

liftPass :: Monad m => (m (Maybe a, w -> w) -> m (Maybe a)) -> MaybeT m (a, w -> w) -> MaybeT m aSource

Lift a `pass` operation to the new monad.