monadLib-3.10.1: A collection of monad transformers.

Safe Haskell | Safe
Language | Haskell2010

MonadLib

Contents

- Types
- Lifting
- Effect Classes
- Execution
  - Eliminating Effects
  - Nested Execution
- Utility functions

Description

This library provides a collection of monad transformers that can be combined to produce various monads.

Synopsis

- data Id a
- data Lift a
- data IdT (m :: Type -> Type) a
- data ReaderT i (m :: Type -> Type) a
- data WriterT i (m :: Type -> Type) a
- data StateT i (m :: Type -> Type) a
- data ExceptionT i (m :: Type -> Type) a
- data ChoiceT (m :: Type -> Type) a
- data ContT i (m :: Type -> Type) a
- class MonadT (t :: (Type -> Type) -> Type -> Type) where
  - lift :: Monad m => m a -> t m a
- class (Monad m, Monad n) => BaseM (m :: Type -> Type) (n :: Type -> Type) | m -> n where
  - inBase :: n a -> m a
- class Monad m => ReaderM (m :: Type -> Type) i | m -> i where
  - ask :: m i
- class Monad m => WriterM (m :: Type -> Type) i | m -> i where
  - put :: i -> m ()
- class Monad m => StateM (m :: Type -> Type) i | m -> i where
  - get :: m i
  - set :: i -> m ()
- class Monad m => ExceptionM (m :: Type -> Type) i | m -> i where
  - raise :: i -> m a
- class Monad m => ContM (m :: Type -> Type) where
  - callWithCC :: ((a -> Label m) -> m a) -> m a
- class Monad m => AbortM (m :: Type -> Type) i where
  - abort :: i -> m a
- data Label (m :: Type -> Type)
- labelCC :: ContM m => a -> m (a, a -> Label m)
- labelCC_ :: ContM m => m (Label m)
- jump :: Label m -> m a
- labelC :: (forall b. m b) -> Label m
- callCC :: ContM m => ((a -> m b) -> m a) -> m a
- runId :: Id a -> a
- runLift :: Lift a -> a
- runIdT :: IdT m a -> m a
- runReaderT :: i -> ReaderT i m a -> m a
- runWriterT :: Monad m => WriterT i m a -> m (a, i)
- runStateT :: i -> StateT i m a -> m (a, i)
- runExceptionT :: ExceptionT i m a -> m (Either i a)
- runContT :: (a -> m i) -> ContT i m a -> m i
- runChoiceT :: Monad m => ChoiceT m a -> m (Maybe (a, ChoiceT m a))
- findOne :: Monad m => ChoiceT m a -> m (Maybe a)
- findAll :: Monad m => ChoiceT m a -> m [a]
- class Monad m => RunM (m :: Type -> Type) a r | m a -> r where
  - runM :: m a -> r
- class ReaderM m i => RunReaderM (m :: Type -> Type) i | m -> i where
  - local :: i -> m a -> m a
- class WriterM m i => RunWriterM (m :: Type -> Type) i | m -> i where
  - collect :: m a -> m (a, i)
- class ExceptionM m i => RunExceptionM (m :: Type -> Type) i | m -> i where
  - try :: m a -> m (Either i a)
- asks :: ReaderM m r => (r -> a) -> m a
- puts :: WriterM m w => (a, w) -> m a
- sets :: StateM m s => (s -> (a, s)) -> m a
- sets_ :: StateM m s => (s -> s) -> m ()
- raises :: ExceptionM m x => Either x a -> m a
- mapReader :: RunReaderM m r => (r -> r) -> m a -> m a
- mapWriter :: RunWriterM m w => (w -> w) -> m a -> m a
- mapException :: RunExceptionM m x => (x -> x) -> m a -> m a
- handle :: RunExceptionM m x => m a -> (x -> m a) -> m a
- type family WithBase (base :: Type -> Type) (layers :: [(Type -> Type) -> Type -> Type]) :: Type -> Type where ...
- module Control.Monad

# Types

The following types define the representations of the computation types supported by the library. Each type adds support for a different effect.

data Id a Source #

Computations with no effects.

#### Instances

Instances details

Applicative Id Source # |
Instance details Defined in MonadLib Methods pure :: a -> Id a Source # (<*>) :: Id (a -> b) -> Id a -> Id b Source # liftA2 :: (a -> b -> c) -> Id a -> Id b -> Id c Source # (*>) :: Id a -> Id b -> Id b Source # (<*) :: Id a -> Id b -> Id a Source #
Functor Id Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> Id a -> Id b Source # (<$) :: a -> Id b -> Id a Source #
Monad Id Source # |
Instance details Defined in MonadLib Methods (>>=) :: Id a -> (a -> Id b) -> Id b Source # (>>) :: Id a -> Id b -> Id b Source # return :: a -> Id a Source #
MonadFix Id Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> Id a) -> Id a Source #
BaseM Id Id Source # |
Instance details Defined in MonadLib Methods inBase :: Id a -> Id a Source #
RunM Id a a Source # |
Instance details Defined in MonadLib Methods runM :: Id a -> a Source #

data Lift a Source #

Computation with no effects (strict).

#### Instances

Instances details

Applicative Lift Source # |
Instance details Defined in MonadLib Methods pure :: a -> Lift a Source # (<*>) :: Lift (a -> b) -> Lift a -> Lift b Source # liftA2 :: (a -> b -> c) -> Lift a -> Lift b -> Lift c Source # (*>) :: Lift a -> Lift b -> Lift b Source # (<*) :: Lift a -> Lift b -> Lift a Source #
Functor Lift Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> Lift a -> Lift b Source # (<$) :: a -> Lift b -> Lift a Source #
Monad Lift Source # |
Instance details Defined in MonadLib Methods (>>=) :: Lift a -> (a -> Lift b) -> Lift b Source # (>>) :: Lift a -> Lift b -> Lift b Source # return :: a -> Lift a Source #
MonadFix Lift Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> Lift a) -> Lift a Source #
BaseM Lift Lift Source # |
Instance details Defined in MonadLib Methods inBase :: Lift a -> Lift a Source #
RunM Lift a a Source # |
Instance details Defined in MonadLib Methods runM :: Lift a -> a Source #

data IdT (m :: Type -> Type) a Source #

Adds no new features. Useful as a placeholder.

#### Instances

Instances details

MonadT IdT Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> IdT m a Source #
MonadPlus m => Alternative (IdT m) Source # |
Instance details Defined in MonadLib Methods empty :: IdT m a Source # (<|>) :: IdT m a -> IdT m a -> IdT m a Source # some :: IdT m a -> IdT m [a] Source # many :: IdT m a -> IdT m [a] Source #
Monad m => Applicative (IdT m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> IdT m a Source # (<*>) :: IdT m (a -> b) -> IdT m a -> IdT m b Source # liftA2 :: (a -> b -> c) -> IdT m a -> IdT m b -> IdT m c Source # (*>) :: IdT m a -> IdT m b -> IdT m b Source # (<*) :: IdT m a -> IdT m b -> IdT m a Source #
Monad m => Functor (IdT m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> IdT m a -> IdT m b Source # (<$) :: a -> IdT m b -> IdT m a Source #
Monad m => Monad (IdT m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: IdT m a -> (a -> IdT m b) -> IdT m b Source # (>>) :: IdT m a -> IdT m b -> IdT m b Source # return :: a -> IdT m a Source #
MonadPlus m => MonadPlus (IdT m) Source # |
Instance details Defined in MonadLib Methods mzero :: IdT m a Source # mplus :: IdT m a -> IdT m a -> IdT m a Source #
MonadFail m => MonadFail (IdT m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> IdT m a Source #
MonadFix m => MonadFix (IdT m) Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> IdT m a) -> IdT m a Source #
ContM m => ContM (IdT m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (IdT m)) -> IdT m a) -> IdT m a Source #
AbortM m i => AbortM (IdT m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> IdT m a Source #
BaseM m n => BaseM (IdT m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> IdT m a Source #
ExceptionM m j => ExceptionM (IdT m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> IdT m a Source #
ReaderM m j => ReaderM (IdT m) j Source # |
Instance details Defined in MonadLib Methods ask :: IdT m j Source #
RunExceptionM m i => RunExceptionM (IdT m) i Source # |
Instance details Defined in MonadLib Methods try :: IdT m a -> IdT m (Either i a) Source #
RunReaderM m j => RunReaderM (IdT m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> IdT m a -> IdT m a Source #
RunWriterM m j => RunWriterM (IdT m) j Source # |
Instance details Defined in MonadLib Methods collect :: IdT m a -> IdT m (a, j) Source #
StateM m j => StateM (IdT m) j Source # |
Instance details Defined in MonadLib Methods get :: IdT m j Source # set :: j -> IdT m () Source #
WriterM m j => WriterM (IdT m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> IdT m () Source #
RunM m a r => RunM (IdT m) a r Source # |
Instance details Defined in MonadLib Methods runM :: IdT m a -> r Source #

data ReaderT i (m :: Type -> Type) a Source #

Add support for propagating a context of type `i`.

#### Instances

Instances details

MonadT (ReaderT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ReaderT i m a Source #
MonadPlus m => Alternative (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods empty :: ReaderT i m a Source # (<|>) :: ReaderT i m a -> ReaderT i m a -> ReaderT i m a Source # some :: ReaderT i m a -> ReaderT i m [a] Source # many :: ReaderT i m a -> ReaderT i m [a] Source #
Monad m => Applicative (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> ReaderT i m a Source # (<*>) :: ReaderT i m (a -> b) -> ReaderT i m a -> ReaderT i m b Source # liftA2 :: (a -> b -> c) -> ReaderT i m a -> ReaderT i m b -> ReaderT i m c Source # (*>) :: ReaderT i m a -> ReaderT i m b -> ReaderT i m b Source # (<*) :: ReaderT i m a -> ReaderT i m b -> ReaderT i m a Source #
Monad m => Functor (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> ReaderT i m a -> ReaderT i m b Source # (<$) :: a -> ReaderT i m b -> ReaderT i m a Source #
Monad m => Monad (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: ReaderT i m a -> (a -> ReaderT i m b) -> ReaderT i m b Source # (>>) :: ReaderT i m a -> ReaderT i m b -> ReaderT i m b Source # return :: a -> ReaderT i m a Source #
MonadPlus m => MonadPlus (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods mzero :: ReaderT i m a Source # mplus :: ReaderT i m a -> ReaderT i m a -> ReaderT i m a Source #
MonadFail m => MonadFail (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> ReaderT i m a Source #
MonadFix m => MonadFix (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> ReaderT i m a) -> ReaderT i m a Source #
ContM m => ContM (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ReaderT i m)) -> ReaderT i m a) -> ReaderT i m a Source #
AbortM m i => AbortM (ReaderT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ReaderT j m a Source #
BaseM m n => BaseM (ReaderT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ReaderT i m a Source #
ExceptionM m j => ExceptionM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ReaderT i m a Source #
Monad m => ReaderM (ReaderT i m) i Source # |
Instance details Defined in MonadLib Methods ask :: ReaderT i m i Source #
RunExceptionM m i => RunExceptionM (ReaderT j m) i Source # |
Instance details Defined in MonadLib Methods try :: ReaderT j m a -> ReaderT j m (Either i a) Source #
Monad m => RunReaderM (ReaderT i m) i Source # |
Instance details Defined in MonadLib Methods local :: i -> ReaderT i m a -> ReaderT i m a Source #
RunWriterM m j => RunWriterM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ReaderT i m a -> ReaderT i m (a, j) Source #
StateM m j => StateM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ReaderT i m j Source # set :: j -> ReaderT i m () Source #
WriterM m j => WriterM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ReaderT i m () Source #
RunM m a r => RunM (ReaderT i m) a (i -> r) Source # |
Instance details Defined in MonadLib Methods runM :: ReaderT i m a -> i -> r Source #

data WriterT i (m :: Type -> Type) a Source #

Add support for collecting values of type `i`. The type `i` should be a monoid, whose unit is used to represent a lack of a value, and whose binary operation is used to combine multiple values. This transformer is strict in its output component.

#### Instances

Instances details

Monoid i => MonadT (WriterT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> WriterT i m a Source #
(MonadPlus m, Monoid i) => Alternative (WriterT i m) Source # |
Instance details Defined in MonadLib Methods empty :: WriterT i m a Source # (<|>) :: WriterT i m a -> WriterT i m a -> WriterT i m a Source # some :: WriterT i m a -> WriterT i m [a] Source # many :: WriterT i m a -> WriterT i m [a] Source #
(Monad m, Monoid i) => Applicative (WriterT i m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> WriterT i m a Source # (<*>) :: WriterT i m (a -> b) -> WriterT i m a -> WriterT i m b Source # liftA2 :: (a -> b -> c) -> WriterT i m a -> WriterT i m b -> WriterT i m c Source # (*>) :: WriterT i m a -> WriterT i m b -> WriterT i m b Source # (<*) :: WriterT i m a -> WriterT i m b -> WriterT i m a Source #
(Monad m, Monoid i) => Functor (WriterT i m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> WriterT i m a -> WriterT i m b Source # (<$) :: a -> WriterT i m b -> WriterT i m a Source #
(Monad m, Monoid i) => Monad (WriterT i m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: WriterT i m a -> (a -> WriterT i m b) -> WriterT i m b Source # (>>) :: WriterT i m a -> WriterT i m b -> WriterT i m b Source # return :: a -> WriterT i m a Source #
(MonadPlus m, Monoid i) => MonadPlus (WriterT i m) Source # |
Instance details Defined in MonadLib Methods mzero :: WriterT i m a Source # mplus :: WriterT i m a -> WriterT i m a -> WriterT i m a Source #
(Monoid i, MonadFail m) => MonadFail (WriterT i m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> WriterT i m a Source #
(MonadFix m, Monoid i) => MonadFix (WriterT i m) Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> WriterT i m a) -> WriterT i m a Source #
(ContM m, Monoid i) => ContM (WriterT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (WriterT i m)) -> WriterT i m a) -> WriterT i m a Source #
(AbortM m i, Monoid j) => AbortM (WriterT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> WriterT j m a Source #
(BaseM m n, Monoid i) => BaseM (WriterT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> WriterT i m a Source #
(ExceptionM m j, Monoid i) => ExceptionM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> WriterT i m a Source #
(ReaderM m j, Monoid i) => ReaderM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: WriterT i m j Source #
(RunExceptionM m i, Monoid j) => RunExceptionM (WriterT j m) i Source # |
Instance details Defined in MonadLib Methods try :: WriterT j m a -> WriterT j m (Either i a) Source #
(RunReaderM m j, Monoid i) => RunReaderM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> WriterT i m a -> WriterT i m a Source #
(Monad m, Monoid i) => RunWriterM (WriterT i m) i Source # |
Instance details Defined in MonadLib Methods collect :: WriterT i m a -> WriterT i m (a, i) Source #
(StateM m j, Monoid i) => StateM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods get :: WriterT i m j Source # set :: j -> WriterT i m () Source #
(Monad m, Monoid i) => WriterM (WriterT i m) i Source # |
Instance details Defined in MonadLib Methods put :: i -> WriterT i m () Source #
(Monoid i, RunM m (a, i) r) => RunM (WriterT i m) a r Source # |
Instance details Defined in MonadLib Methods runM :: WriterT i m a -> r Source #

data StateT i (m :: Type -> Type) a Source #

Add support for threading state of type `i`.

#### Instances

Instances details

MonadT (StateT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> StateT i m a Source #
MonadPlus m => Alternative (StateT i m) Source # |
Instance details Defined in MonadLib Methods empty :: StateT i m a Source # (<|>) :: StateT i m a -> StateT i m a -> StateT i m a Source # some :: StateT i m a -> StateT i m [a] Source # many :: StateT i m a -> StateT i m [a] Source #
Monad m => Applicative (StateT i m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> StateT i m a Source # (<*>) :: StateT i m (a -> b) -> StateT i m a -> StateT i m b Source # liftA2 :: (a -> b -> c) -> StateT i m a -> StateT i m b -> StateT i m c Source # (*>) :: StateT i m a -> StateT i m b -> StateT i m b Source # (<*) :: StateT i m a -> StateT i m b -> StateT i m a Source #
Monad m => Functor (StateT i m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> StateT i m a -> StateT i m b Source # (<$) :: a -> StateT i m b -> StateT i m a Source #
Monad m => Monad (StateT i m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: StateT i m a -> (a -> StateT i m b) -> StateT i m b Source # (>>) :: StateT i m a -> StateT i m b -> StateT i m b Source # return :: a -> StateT i m a Source #
MonadPlus m => MonadPlus (StateT i m) Source # |
Instance details Defined in MonadLib Methods mzero :: StateT i m a Source # mplus :: StateT i m a -> StateT i m a -> StateT i m a Source #
MonadFail m => MonadFail (StateT i m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> StateT i m a Source #
MonadFix m => MonadFix (StateT i m) Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> StateT i m a) -> StateT i m a Source #
ContM m => ContM (StateT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (StateT i m)) -> StateT i m a) -> StateT i m a Source #
AbortM m i => AbortM (StateT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> StateT j m a Source #
BaseM m n => BaseM (StateT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> StateT i m a Source #
ExceptionM m j => ExceptionM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> StateT i m a Source #
ReaderM m j => ReaderM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: StateT i m j Source #
RunExceptionM m i => RunExceptionM (StateT j m) i Source # |
Instance details Defined in MonadLib Methods try :: StateT j m a -> StateT j m (Either i a) Source #
RunReaderM m j => RunReaderM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> StateT i m a -> StateT i m a Source #
RunWriterM m j => RunWriterM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: StateT i m a -> StateT i m (a, j) Source #
Monad m => StateM (StateT i m) i Source # |
Instance details Defined in MonadLib Methods get :: StateT i m i Source # set :: i -> StateT i m () Source #
WriterM m j => WriterM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> StateT i m () Source #
RunM m (a, i) r => RunM (StateT i m) a (i -> r) Source # |
Instance details Defined in MonadLib Methods runM :: StateT i m a -> i -> r Source #

data ExceptionT i (m :: Type -> Type) a Source #

Add support for exceptions of type `i`.

#### Instances

Instances details

MonadT (ExceptionT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ExceptionT i m a Source #
MonadPlus m => Alternative (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods empty :: ExceptionT i m a Source # (<|>) :: ExceptionT i m a -> ExceptionT i m a -> ExceptionT i m a Source # some :: ExceptionT i m a -> ExceptionT i m [a] Source # many :: ExceptionT i m a -> ExceptionT i m [a] Source #
Monad m => Applicative (ExceptionT i m) Source # |

Instance details

Defined in MonadLib

Methods

pure :: a -> ExceptionT i m a Source #

(<*>) :: ExceptionT i m (a -> b) -> ExceptionT i m a -> ExceptionT i m b Source #

liftA2 :: (a -> b -> c) -> ExceptionT i m a -> ExceptionT i m b -> ExceptionT i m c Source #

(*>) :: ExceptionT i m a -> ExceptionT i m b -> ExceptionT i m b Source #

(<*) :: ExceptionT i m a -> ExceptionT i m b -> ExceptionT i m a Source #

Monad m => Functor (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> ExceptionT i m a -> ExceptionT i m b Source # (<$) :: a -> ExceptionT i m b -> ExceptionT i m a Source #
Monad m => Monad (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: ExceptionT i m a -> (a -> ExceptionT i m b) -> ExceptionT i m b Source # (>>) :: ExceptionT i m a -> ExceptionT i m b -> ExceptionT i m b Source # return :: a -> ExceptionT i m a Source #
MonadPlus m => MonadPlus (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods mzero :: ExceptionT i m a Source # mplus :: ExceptionT i m a -> ExceptionT i m a -> ExceptionT i m a Source #
MonadFail m => MonadFail (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> ExceptionT i m a Source #
MonadFix m => MonadFix (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods mfix :: (a -> ExceptionT i m a) -> ExceptionT i m a Source #
ContM m => ContM (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ExceptionT i m)) -> ExceptionT i m a) -> ExceptionT i m a Source #
AbortM m i => AbortM (ExceptionT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ExceptionT j m a Source #
BaseM m n => BaseM (ExceptionT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ExceptionT i m a Source #
Monad m => ExceptionM (ExceptionT i m) i Source # |
Instance details Defined in MonadLib Methods raise :: i -> ExceptionT i m a Source #
ReaderM m j => ReaderM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: ExceptionT i m j Source #
Monad m => RunExceptionM (ExceptionT i m) i Source # |
Instance details Defined in MonadLib Methods try :: ExceptionT i m a -> ExceptionT i m (Either i a) Source #
RunReaderM m j => RunReaderM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> ExceptionT i m a -> ExceptionT i m a Source #
RunWriterM m j => RunWriterM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ExceptionT i m a -> ExceptionT i m (a, j) Source #
StateM m j => StateM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ExceptionT i m j Source # set :: j -> ExceptionT i m () Source #
WriterM m j => WriterM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ExceptionT i m () Source #
RunM m (Either i a) r => RunM (ExceptionT i m) a r Source # |
Instance details Defined in MonadLib Methods runM :: ExceptionT i m a -> r Source #

About the `WriterM` instance: If an exception is risen while we are collecting output, then the output is lost. If the output is important, then use `try` to ensure that no exception may occur. Example:

    do (r,w) <- collect (try m)
       case r of
         Left err -> ...do something...
         Right a  -> ...do something...

data ChoiceT (m :: Type -> Type) a Source #

Add support for multiple answers.

#### Instances

Instances details

MonadT ChoiceT Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ChoiceT m a Source #
Monad m => Alternative (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods empty :: ChoiceT m a Source # (<|>) :: ChoiceT m a -> ChoiceT m a -> ChoiceT m a Source # some :: ChoiceT m a -> ChoiceT m [a] Source # many :: ChoiceT m a -> ChoiceT m [a] Source #
Monad m => Applicative (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> ChoiceT m a Source # (<*>) :: ChoiceT m (a -> b) -> ChoiceT m a -> ChoiceT m b Source # liftA2 :: (a -> b -> c) -> ChoiceT m a -> ChoiceT m b -> ChoiceT m c Source # (*>) :: ChoiceT m a -> ChoiceT m b -> ChoiceT m b Source # (<*) :: ChoiceT m a -> ChoiceT m b -> ChoiceT m a Source #
Monad m => Functor (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> ChoiceT m a -> ChoiceT m b Source # (<$) :: a -> ChoiceT m b -> ChoiceT m a Source #
Monad m => Monad (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: ChoiceT m a -> (a -> ChoiceT m b) -> ChoiceT m b Source # (>>) :: ChoiceT m a -> ChoiceT m b -> ChoiceT m b Source # return :: a -> ChoiceT m a Source #
Monad m => MonadPlus (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods mzero :: ChoiceT m a Source # mplus :: ChoiceT m a -> ChoiceT m a -> ChoiceT m a Source #
MonadFail m => MonadFail (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> ChoiceT m a Source #
ContM m => ContM (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ChoiceT m)) -> ChoiceT m a) -> ChoiceT m a Source #
AbortM m i => AbortM (ChoiceT m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ChoiceT m a Source #
BaseM m n => BaseM (ChoiceT m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ChoiceT m a Source #
ExceptionM m j => ExceptionM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ChoiceT m a Source #
ReaderM m j => ReaderM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods ask :: ChoiceT m j Source #
StateM m j => StateM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods get :: ChoiceT m j Source # set :: j -> ChoiceT m () Source #
WriterM m j => WriterM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ChoiceT m () Source #
RunM m (Maybe (a, ChoiceT m a)) r => RunM (ChoiceT m) a r Source # |
Instance details Defined in MonadLib Methods runM :: ChoiceT m a -> r Source #

data ContT i (m :: Type -> Type) a Source #

Add support for continuations within a prompt of type `i`.

#### Instances

Instances details

MonadT (ContT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ContT i m a Source #
MonadPlus m => Alternative (ContT i m) Source # |
Instance details Defined in MonadLib Methods empty :: ContT i m a Source # (<|>) :: ContT i m a -> ContT i m a -> ContT i m a Source # some :: ContT i m a -> ContT i m [a] Source # many :: ContT i m a -> ContT i m [a] Source #
Monad m => Applicative (ContT i m) Source # |
Instance details Defined in MonadLib Methods pure :: a -> ContT i m a Source # (<*>) :: ContT i m (a -> b) -> ContT i m a -> ContT i m b Source # liftA2 :: (a -> b -> c) -> ContT i m a -> ContT i m b -> ContT i m c Source # (*>) :: ContT i m a -> ContT i m b -> ContT i m b Source # (<*) :: ContT i m a -> ContT i m b -> ContT i m a Source #
Monad m => Functor (ContT i m) Source # |
Instance details Defined in MonadLib Methods fmap :: (a -> b) -> ContT i m a -> ContT i m b Source # (<$) :: a -> ContT i m b -> ContT i m a Source #
Monad m => Monad (ContT i m) Source # |
Instance details Defined in MonadLib Methods (>>=) :: ContT i m a -> (a -> ContT i m b) -> ContT i m b Source # (>>) :: ContT i m a -> ContT i m b -> ContT i m b Source # return :: a -> ContT i m a Source #
MonadPlus m => MonadPlus (ContT i m) Source # |
Instance details Defined in MonadLib Methods mzero :: ContT i m a Source # mplus :: ContT i m a -> ContT i m a -> ContT i m a Source #
MonadFail m => MonadFail (ContT i m) Source # |
Instance details Defined in MonadLib Methods fail :: String -> ContT i m a Source #
Monad m => ContM (ContT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ContT i m)) -> ContT i m a) -> ContT i m a Source #
Monad m => AbortM (ContT i m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ContT i m a Source #
BaseM m n => BaseM (ContT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ContT i m a Source #
ExceptionM m j => ExceptionM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ContT i m a Source #
ReaderM m j => ReaderM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: ContT i m j Source #
RunReaderM m j => RunReaderM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> ContT i m a -> ContT i m a Source #
(RunWriterM m j, MonadFix m) => RunWriterM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ContT i m a -> ContT i m (a, j) Source #
StateM m j => StateM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ContT i m j Source # set :: j -> ContT i m () Source #
WriterM m j => WriterM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ContT i m () Source #
RunM m i r => RunM (ContT i m) a ((a -> m i) -> r) Source # |
Instance details Defined in MonadLib Methods runM :: ContT i m a -> (a -> m i) -> r Source #

# Lifting

The following operations allow us to promote computations in the underlying monad to computations that support an extra effect. Computations defined in this way do not make use of the new effect but can be combined with other operations that utilize the effect.

class MonadT (t :: (Type -> Type) -> Type -> Type) where Source #

Methods

lift :: Monad m => m a -> t m a Source #

Promote a computation from the underlying monad.

#### Instances

Instances details

MonadT ChoiceT Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ChoiceT m a Source #
MonadT IdT Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> IdT m a Source #
MonadT (ContT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ContT i m a Source #
MonadT (ExceptionT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ExceptionT i m a Source #
MonadT (ReaderT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> ReaderT i m a Source #
MonadT (StateT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> StateT i m a Source #
Monoid i => MonadT (WriterT i) Source # |
Instance details Defined in MonadLib Methods lift :: Monad m => m a -> WriterT i m a Source #

class (Monad m, Monad n) => BaseM (m :: Type -> Type) (n :: Type -> Type) | m -> n where Source #

Methods

inBase :: n a -> m a Source #

Promote a computation from the base monad.

#### Instances

Instances details

BaseM IO IO Source # |
Instance details Defined in MonadLib Methods inBase :: IO a -> IO a Source #
BaseM Id Id Source # |
Instance details Defined in MonadLib Methods inBase :: Id a -> Id a Source #
BaseM Lift Lift Source # |
Instance details Defined in MonadLib Methods inBase :: Lift a -> Lift a Source #
BaseM Maybe Maybe Source # |
Instance details Defined in MonadLib Methods inBase :: Maybe a -> Maybe a Source #
BaseM [] [] Source # |
Instance details Defined in MonadLib Methods inBase :: [a] -> [a] Source #
BaseM m n => BaseM (ChoiceT m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ChoiceT m a Source #
BaseM m n => BaseM (IdT m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> IdT m a Source #
BaseM (ST s) (ST s) Source # |
Instance details Defined in MonadLib Methods inBase :: ST s a -> ST s a Source #
BaseM (Cont i) (Cont i) Source # |
Instance details Defined in MonadLib.Monads Methods inBase :: Cont i a -> Cont i a Source #
BaseM (Exception i) (Exception i) Source # |
Instance details Defined in MonadLib.Monads Methods inBase :: Exception i a -> Exception i a Source #
BaseM (Reader i) (Reader i) Source # |
Instance details Defined in MonadLib.Monads Methods inBase :: Reader i a -> Reader i a Source #
BaseM (State i) (State i) Source # |
Instance details Defined in MonadLib.Monads Methods inBase :: State i a -> State i a Source #
Monoid i => BaseM (Writer i) (Writer i) Source # |
Instance details Defined in MonadLib.Monads Methods inBase :: Writer i a -> Writer i a Source #
BaseM m n => BaseM (ContT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ContT i m a Source #
BaseM m n => BaseM (ExceptionT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ExceptionT i m a Source #
BaseM m n => BaseM (ReaderT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> ReaderT i m a Source #
BaseM m n => BaseM (StateT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> StateT i m a Source #
(BaseM m n, Monoid i) => BaseM (WriterT i m) n Source # |
Instance details Defined in MonadLib Methods inBase :: n a -> WriterT i m a Source #

# Effect Classes

The following classes define overloaded operations that can be used to define effectful computations.

class Monad m => ReaderM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that provide access to a context of type `i`.

Methods

ask :: m i Source #

Get the context.

#### Instances

Instances details

ReaderM m j => ReaderM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods ask :: ChoiceT m j Source #
ReaderM m j => ReaderM (IdT m) j Source # |
Instance details Defined in MonadLib Methods ask :: IdT m j Source #
ReaderM (Reader i) i Source # |
Instance details Defined in MonadLib.Monads Methods ask :: Reader i i Source #
ReaderM m j => ReaderM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: ContT i m j Source #
ReaderM m j => ReaderM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: ExceptionT i m j Source #
Monad m => ReaderM (ReaderT i m) i Source # |
Instance details Defined in MonadLib Methods ask :: ReaderT i m i Source #
ReaderM m j => ReaderM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: StateT i m j Source #
(ReaderM m j, Monoid i) => ReaderM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods ask :: WriterT i m j Source #

class Monad m => WriterM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that can collect values of type `i`.

Methods

put :: i -> m () Source #

Add a value to the collection.

#### Instances

Instances details

WriterM m j => WriterM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ChoiceT m () Source #
WriterM m j => WriterM (IdT m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> IdT m () Source #
Monoid i => WriterM (Writer i) i Source # |
Instance details Defined in MonadLib.Monads Methods put :: i -> Writer i () Source #
WriterM m j => WriterM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ContT i m () Source #
WriterM m j => WriterM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ExceptionT i m () Source #
WriterM m j => WriterM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> ReaderT i m () Source #
WriterM m j => WriterM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods put :: j -> StateT i m () Source #
(Monad m, Monoid i) => WriterM (WriterT i m) i Source # |
Instance details Defined in MonadLib Methods put :: i -> WriterT i m () Source #

class Monad m => StateM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that propagate a state component of type `i`.

Methods

get :: m i Source #

Get the state.

set :: i -> m () Source #

Set the state.

#### Instances

Instances details

StateM m j => StateM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods get :: ChoiceT m j Source # set :: j -> ChoiceT m () Source #
StateM m j => StateM (IdT m) j Source # |
Instance details Defined in MonadLib Methods get :: IdT m j Source # set :: j -> IdT m () Source #
StateM (State i) i Source # |
Instance details Defined in MonadLib.Monads Methods get :: State i i Source # set :: i -> State i () Source #
StateM m j => StateM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ContT i m j Source # set :: j -> ContT i m () Source #
StateM m j => StateM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ExceptionT i m j Source # set :: j -> ExceptionT i m () Source #
StateM m j => StateM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods get :: ReaderT i m j Source # set :: j -> ReaderT i m () Source #
Monad m => StateM (StateT i m) i Source # |
Instance details Defined in MonadLib Methods get :: StateT i m i Source # set :: i -> StateT i m () Source #
(StateM m j, Monoid i) => StateM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods get :: WriterT i m j Source # set :: j -> WriterT i m () Source #

class Monad m => ExceptionM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that support raising exceptions of type `i`.

Methods

raise :: i -> m a Source #

Raise an exception.

#### Instances

Instances details

ExceptionM IO SomeException Source # |
Instance details Defined in MonadLib Methods raise :: SomeException -> IO a Source #
ExceptionM m j => ExceptionM (ChoiceT m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ChoiceT m a Source #
ExceptionM m j => ExceptionM (IdT m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> IdT m a Source #
ExceptionM (Exception i) i Source # |
Instance details Defined in MonadLib.Monads Methods raise :: i -> Exception i a Source #
ExceptionM m j => ExceptionM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ContT i m a Source #
Monad m => ExceptionM (ExceptionT i m) i Source # |
Instance details Defined in MonadLib Methods raise :: i -> ExceptionT i m a Source #
ExceptionM m j => ExceptionM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> ReaderT i m a Source #
ExceptionM m j => ExceptionM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> StateT i m a Source #
(ExceptionM m j, Monoid i) => ExceptionM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods raise :: j -> WriterT i m a Source #

class Monad m => ContM (m :: Type -> Type) where Source #

Classifies monads that provide access to a computation's continuation.

Methods

callWithCC :: ((a -> Label m) -> m a) -> m a Source #

Capture the current continuation.

#### Instances

Instances details

ContM m => ContM (ChoiceT m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ChoiceT m)) -> ChoiceT m a) -> ChoiceT m a Source #
ContM m => ContM (IdT m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (IdT m)) -> IdT m a) -> IdT m a Source #
ContM (Cont i) Source # |
Instance details Defined in MonadLib.Monads Methods callWithCC :: ((a -> Label (Cont i)) -> Cont i a) -> Cont i a Source #
Monad m => ContM (ContT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ContT i m)) -> ContT i m a) -> ContT i m a Source #
ContM m => ContM (ExceptionT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ExceptionT i m)) -> ExceptionT i m a) -> ExceptionT i m a Source #
ContM m => ContM (ReaderT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (ReaderT i m)) -> ReaderT i m a) -> ReaderT i m a Source #
ContM m => ContM (StateT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (StateT i m)) -> StateT i m a) -> StateT i m a Source #
(ContM m, Monoid i) => ContM (WriterT i m) Source # |
Instance details Defined in MonadLib Methods callWithCC :: ((a -> Label (WriterT i m)) -> WriterT i m a) -> WriterT i m a Source #

class Monad m => AbortM (m :: Type -> Type) i where Source #

Classifies monads that support aborting the program and returning a given final result of type `i`.

Methods

abort :: i -> m a Source #

Abort the program with the given value as final result.

#### Instances

Instances details

AbortM IO ExitCode Source # |
Instance details Defined in MonadLib Methods abort :: ExitCode -> IO a Source #
AbortM m i => AbortM (ChoiceT m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ChoiceT m a Source #
AbortM m i => AbortM (IdT m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> IdT m a Source #
Monad m => AbortM (ContT i m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ContT i m a Source #
AbortM m i => AbortM (ExceptionT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ExceptionT j m a Source #
AbortM m i => AbortM (ReaderT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> ReaderT j m a Source #
AbortM m i => AbortM (StateT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> StateT j m a Source #
(AbortM m i, Monoid j) => AbortM (WriterT j m) i Source # |
Instance details Defined in MonadLib Methods abort :: i -> WriterT j m a Source #

data Label (m :: Type -> Type) Source #

An explicit representation for monadic continuations.

labelCC :: ContM m => a -> m (a, a -> Label m) Source #

Capture the current continuation. This function is like `return`, except that it also captures the current continuation. Later, we can use `jump` to repeat the computation from this point onwards but with a possibly different value.

labelCC_ :: ContM m => m (Label m) Source #

Capture the current continuation. Later we can use `jump` to restart the program from this point.

jump :: Label m -> m a Source #

Restart a previously captured computation.

labelC :: (forall b. m b) -> Label m Source #

Label a given continuation.

callCC :: ContM m => ((a -> m b) -> m a) -> m a Source #

A version of `callWithCC` that avoids the need for an explicit use of the `jump` function.

# Execution

## Eliminating Effects

The following functions eliminate the outermost effect of a computation by translating a computation into an equivalent computation in the underlying monad. (The exceptions are `Id` and `Lift` which are not transformers but ordinary monads and so, their run operations simply eliminate the monad.)

runId :: Id a -> a Source #

Get the result of a pure computation.

runLift :: Lift a -> a Source #

Get the result of a pure strict computation.

runIdT :: IdT m a -> m a Source #

Remove an identity layer.

runReaderT :: i -> ReaderT i m a -> m a Source #

Execute a reader computation in the given context.

runWriterT :: Monad m => WriterT i m a -> m (a, i) Source #

Execute a writer computation. Returns the result and the collected output.

runStateT :: i -> StateT i m a -> m (a, i) Source #

Execute a stateful computation in the given initial state. The second component of the result is the final state.

runExceptionT :: ExceptionT i m a -> m (Either i a) Source #

Execute a computation with exceptions. Successful results are tagged with `Right`, exceptional results are tagged with `Left`.

runContT :: (a -> m i) -> ContT i m a -> m i Source #

Execute a computation with the given continuation.

runChoiceT :: Monad m => ChoiceT m a -> m (Maybe (a, ChoiceT m a)) Source #

Execute a computation that may return multiple answers. The resulting computation returns `Nothing` if no answers were found, or `Just (answer,new_comp)`, where `answer` is an answer, and `new_comp` is a computation that may produce more answers. The search is depth-first and left-biased with respect to the `mplus` operation.

findOne :: Monad m => ChoiceT m a -> m (Maybe a) Source #

Execute a computation that may return multiple answers, returning at most one answer.

findAll :: Monad m => ChoiceT m a -> m [a] Source #

Execute a computation that may return multiple answers, collecting all possible answers.

class Monad m => RunM (m :: Type -> Type) a r | m a -> r where Source #

Generalized running.

Methods

runM :: m a -> r Source #

#### Instances

Instances details

RunM Id a a Source # |
Instance details Defined in MonadLib Methods runM :: Id a -> a Source #
RunM Lift a a Source # |
Instance details Defined in MonadLib Methods runM :: Lift a -> a Source #
RunM IO a (IO a) Source # |
Instance details Defined in MonadLib Methods runM :: IO a -> IO a Source #
RunM m (Maybe (a, ChoiceT m a)) r => RunM (ChoiceT m) a r Source # |
Instance details Defined in MonadLib Methods runM :: ChoiceT m a -> r Source #
RunM m a r => RunM (IdT m) a r Source # |
Instance details Defined in MonadLib Methods runM :: IdT m a -> r Source #
RunM m (Either i a) r => RunM (ExceptionT i m) a r Source # |
Instance details Defined in MonadLib Methods runM :: ExceptionT i m a -> r Source #
(Monoid i, RunM m (a, i) r) => RunM (WriterT i m) a r Source # |
Instance details Defined in MonadLib Methods runM :: WriterT i m a -> r Source #
RunM m i r => RunM (ContT i m) a ((a -> m i) -> r) Source # |
Instance details Defined in MonadLib Methods runM :: ContT i m a -> (a -> m i) -> r Source #
RunM m a r => RunM (ReaderT i m) a (i -> r) Source # |
Instance details Defined in MonadLib Methods runM :: ReaderT i m a -> i -> r Source #
RunM m (a, i) r => RunM (StateT i m) a (i -> r) Source # |
Instance details Defined in MonadLib Methods runM :: StateT i m a -> i -> r Source #

## Nested Execution

The following classes define operations that are overloaded versions of the `run` operations. Unlike the `run` operations, these functions do not change the type of the computation (i.e., they do not remove a layer). Instead, they perform the effects in a ``separate effect thread''.

class ReaderM m i => RunReaderM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that support changing the context for a sub-computation.

Methods

local :: i -> m a -> m a Source #

Change the context for the duration of a sub-computation.

#### Instances

Instances details

RunReaderM m j => RunReaderM (IdT m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> IdT m a -> IdT m a Source #
RunReaderM (Reader i) i Source # |
Instance details Defined in MonadLib.Monads Methods local :: i -> Reader i a -> Reader i a Source #
RunReaderM m j => RunReaderM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> ContT i m a -> ContT i m a Source #
RunReaderM m j => RunReaderM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> ExceptionT i m a -> ExceptionT i m a Source #
Monad m => RunReaderM (ReaderT i m) i Source # |
Instance details Defined in MonadLib Methods local :: i -> ReaderT i m a -> ReaderT i m a Source #
RunReaderM m j => RunReaderM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> StateT i m a -> StateT i m a Source #
(RunReaderM m j, Monoid i) => RunReaderM (WriterT i m) j Source # |
Instance details Defined in MonadLib Methods local :: j -> WriterT i m a -> WriterT i m a Source #

class WriterM m i => RunWriterM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that support collecting the output of a sub-computation.

Methods

collect :: m a -> m (a, i) Source #

Collect the output from a sub-computation.

#### Instances

Instances details

RunWriterM m j => RunWriterM (IdT m) j Source # |
Instance details Defined in MonadLib Methods collect :: IdT m a -> IdT m (a, j) Source #
Monoid i => RunWriterM (Writer i) i Source # |
Instance details Defined in MonadLib.Monads Methods collect :: Writer i a -> Writer i (a, i) Source #
(RunWriterM m j, MonadFix m) => RunWriterM (ContT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ContT i m a -> ContT i m (a, j) Source #
RunWriterM m j => RunWriterM (ExceptionT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ExceptionT i m a -> ExceptionT i m (a, j) Source #
RunWriterM m j => RunWriterM (ReaderT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: ReaderT i m a -> ReaderT i m (a, j) Source #
RunWriterM m j => RunWriterM (StateT i m) j Source # |
Instance details Defined in MonadLib Methods collect :: StateT i m a -> StateT i m (a, j) Source #
(Monad m, Monoid i) => RunWriterM (WriterT i m) i Source # |
Instance details Defined in MonadLib Methods collect :: WriterT i m a -> WriterT i m (a, i) Source #

class ExceptionM m i => RunExceptionM (m :: Type -> Type) i | m -> i where Source #

Classifies monads that support handling of exceptions.

Methods

try :: m a -> m (Either i a) Source #

Convert computations that may raise an exception into computations that do not raise exception but instead, yield a tagged results. Exceptions are tagged with Left, successful computations are tagged with Right.

#### Instances

Instances details

RunExceptionM IO SomeException Source # |
Instance details Defined in MonadLib Methods try :: IO a -> IO (Either SomeException a) Source #
RunExceptionM m i => RunExceptionM (IdT m) i Source # |
Instance details Defined in MonadLib Methods try :: IdT m a -> IdT m (Either i a) Source #
RunExceptionM (Exception i) i Source # |
Instance details Defined in MonadLib.Monads Methods try :: Exception i a -> Exception i (Either i a) Source #
Monad m => RunExceptionM (ExceptionT i m) i Source # |
Instance details Defined in MonadLib Methods try :: ExceptionT i m a -> ExceptionT i m (Either i a) Source #
RunExceptionM m i => RunExceptionM (ReaderT j m) i Source # |
Instance details Defined in MonadLib Methods try :: ReaderT j m a -> ReaderT j m (Either i a) Source #
RunExceptionM m i => RunExceptionM (StateT j m) i Source # |
Instance details Defined in MonadLib Methods try :: StateT j m a -> StateT j m (Either i a) Source #
(RunExceptionM m i, Monoid j) => RunExceptionM (WriterT j m) i Source # |
Instance details Defined in MonadLib Methods try :: WriterT j m a -> WriterT j m (Either i a) Source #

# Utility functions

asks :: ReaderM m r => (r -> a) -> m a Source #

Apply a function to the environment. Useful for accessing environmnt components.

puts :: WriterM m w => (a, w) -> m a Source #

Add content the output and return a result.

sets :: StateM m s => (s -> (a, s)) -> m a Source #

Update the state and return a result.

sets_ :: StateM m s => (s -> s) -> m () Source #

Updates the state with the given function.

raises :: ExceptionM m x => Either x a -> m a Source #

Either raise an exception or return a value. `Left` values signify the we should raise an exception, `Right` values indicate success.

mapReader :: RunReaderM m r => (r -> r) -> m a -> m a Source #

Modify the environment for the duration of a computation.

mapWriter :: RunWriterM m w => (w -> w) -> m a -> m a Source #

Modify the output of a computation.

mapException :: RunExceptionM m x => (x -> x) -> m a -> m a Source #

Modify the exception that was risen by a computation.

handle :: RunExceptionM m x => m a -> (x -> m a) -> m a Source #

Apply the given exception handler, if a computation raises an exception.

type family WithBase (base :: Type -> Type) (layers :: [(Type -> Type) -> Type -> Type]) :: Type -> Type where ... Source #

A convenience type family for defining stacks of monads. The first entry in the list is the top-most layer of the monad stack (i.e., the one that is furtherest from the base). For example:

    newtype M a = M { unM ::
      WithBase IO
        '[ ReaderT    Int
         , StateT     Char
         , ExceptionT String
         ] a
      }

is equivalent to:

    newtype M a = M { unM ::
      ReaderT    Int      (
      StateT     Char     (
      ExceptionT String
      IO                  )) a
      }

Equations

WithBase b ('[] :: [(Type -> Type) -> Type -> Type]) = b |
WithBase b (f ': fs) = f (WithBase b fs) |

module Control.Monad