This library provides a collection of monad transformers that can be combined to produce various monads.
- data Id a
- data ReaderT i m a
- data WriterT i m a
- data StateT i m a
- data ExceptionT i m a
- data ContT i m a
- class MonadT t where
- class (Monad m, Monad n) => BaseM m n | m -> n where
- inBase :: n a -> m a
- class Monad m => ReaderM m i | m -> i where
- ask :: m i
- class Monad m => WriterM m i | m -> i where
- class Monad m => StateM m i | m -> i where
- class Monad m => ExceptionM m i | m -> i where
- raise :: i -> m a
- class Monad m => ContM m where
- callCC :: ((a -> m b) -> m a) -> m a
- data Label m a
- labelCC :: ContM m => a -> m (a, Label m a)
- jump :: ContM m => a -> Label m a -> m b
- runId :: Id a -> a
- runReaderT :: i -> ReaderT i m a -> m a
- runWriterT :: 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
- class ReaderM m i => RunReaderM m i | m -> i where
- local :: i -> m a -> m a
- class WriterM m i => RunWriterM m i | m -> i where
- collect :: m a -> m (a, i)
- class StateM m i => RunStateM m i | m -> i where
- runS :: i -> m a -> m (a, i)
- class ExceptionM m i => RunExceptionM m i | m -> i where
- version :: (Int, Int, Int)
- 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.
Add support for propagating a context.
MonadT (ReaderT i) | |
Monad m => Monad (ReaderT i m) | |
Monad m => Functor (ReaderT i m) | |
MonadFix m => MonadFix (ReaderT i m) | |
MonadPlus m => MonadPlus (ReaderT i m) | |
ContM m => ContM (ReaderT i m) | |
RunExceptionM m i => RunExceptionM (ReaderT j m) i | |
RunStateM m j => RunStateM (ReaderT i m) j | |
RunWriterM m j => RunWriterM (ReaderT i m) j | |
Monad m => RunReaderM (ReaderT i m) i | |
ExceptionM m j => ExceptionM (ReaderT i m) j | |
StateM m j => StateM (ReaderT i m) j | |
WriterM m j => WriterM (ReaderT i m) j | |
Monad m => ReaderM (ReaderT i m) i | |
BaseM m n => BaseM (ReaderT i m) n |
Add support for collecting values.
Monoid i => MonadT (WriterT i) | |
(Monad m, Monoid i) => Monad (WriterT i m) | |
(Monad m, Monoid i) => Functor (WriterT i m) | |
(MonadFix m, Monoid i) => MonadFix (WriterT i m) | |
(MonadPlus m, Monoid i) => MonadPlus (WriterT i m) | |
(ContM m, Monoid i) => ContM (WriterT i m) | |
(RunExceptionM m i, Monoid j) => RunExceptionM (WriterT j m) i | |
(RunStateM m j, Monoid i) => RunStateM (WriterT i m) j | |
(Monad m, Monoid i) => RunWriterM (WriterT i m) i | |
(RunReaderM m j, Monoid i) => RunReaderM (WriterT i m) j | |
(ExceptionM m j, Monoid i) => ExceptionM (WriterT i m) j | |
(StateM m j, Monoid i) => StateM (WriterT i m) j | |
(Monad m, Monoid i) => WriterM (WriterT i m) i | |
(ReaderM m j, Monoid i) => ReaderM (WriterT i m) j | |
(BaseM m n, Monoid i) => BaseM (WriterT i m) n |
Add support for threading state.
MonadT (StateT i) | |
Monad m => Monad (StateT i m) | |
Monad m => Functor (StateT i m) | |
MonadFix m => MonadFix (StateT i m) | |
MonadPlus m => MonadPlus (StateT i m) | |
ContM m => ContM (StateT i m) | |
RunExceptionM m i => RunExceptionM (StateT j m) i | |
Monad m => RunStateM (StateT i m) i | |
RunWriterM m j => RunWriterM (StateT i m) j | |
RunReaderM m j => RunReaderM (StateT i m) j | |
ExceptionM m j => ExceptionM (StateT i m) j | |
Monad m => StateM (StateT i m) i | |
WriterM m j => WriterM (StateT i m) j | |
ReaderM m j => ReaderM (StateT i m) j | |
BaseM m n => BaseM (StateT i m) n |
data ExceptionT i m a Source
Add support for exceptions.
MonadT (ExceptionT i) | |
Monad m => Monad (ExceptionT i m) | |
Monad m => Functor (ExceptionT i m) | |
MonadFix m => MonadFix (ExceptionT i m) | |
MonadPlus m => MonadPlus (ExceptionT i m) | |
ContM m => ContM (ExceptionT i m) | |
Monad m => RunExceptionM (ExceptionT i m) i | |
RunStateM m j => RunStateM (ExceptionT i m) j | |
RunWriterM m j => RunWriterM (ExceptionT i m) j | |
RunReaderM m j => RunReaderM (ExceptionT i m) j | |
Monad m => ExceptionM (ExceptionT i m) i | |
StateM m j => StateM (ExceptionT i m) j | |
WriterM m j => WriterM (ExceptionT i m) j | |
ReaderM m j => ReaderM (ExceptionT i m) j | |
BaseM m n => BaseM (ExceptionT i m) n |
Add support for jumps.
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 (Monad m, Monad n) => BaseM m n | m -> n whereSource
BaseM [] [] | |
BaseM IO IO | |
BaseM Maybe Maybe | |
BaseM Id Id | |
BaseM (Cont i) (Cont i) | |
BaseM (Exception i) (Exception i) | |
BaseM (State i) (State i) | |
Monoid i => BaseM (Writer i) (Writer i) | |
BaseM (Reader i) (Reader i) | |
BaseM m n => BaseM (ContT i m) n | |
BaseM m n => BaseM (ExceptionT i m) n | |
BaseM m n => BaseM (StateT i m) n | |
(BaseM m n, Monoid i) => BaseM (WriterT i m) n | |
BaseM m n => BaseM (ReaderT i m) n |
Effect Classes
The following classes define overloaded operations that can be used to define effectful computations.
class Monad m => ReaderM m i | m -> i whereSource
Classifies monads that provide access to a context of type i
.
class Monad m => WriterM m i | m -> i whereSource
Classifies monads that can collect values of type i
.
class Monad m => StateM m i | m -> i whereSource
Classifies monads that propagate a state component of type i
.
class Monad m => ExceptionM m i | m -> i whereSource
Classifies monads that support raising exceptions of type i
.
ExceptionM (Exception i) i | |
ExceptionM m j => ExceptionM (ContT i m) j | |
Monad m => ExceptionM (ExceptionT i m) i | |
ExceptionM m j => ExceptionM (StateT i m) j | |
(ExceptionM m j, Monoid i) => ExceptionM (WriterT i m) j | |
ExceptionM m j => ExceptionM (ReaderT i m) j |
class Monad m => ContM m whereSource
Classifies monads that provide access to a computation's continuation.
jump :: ContM m => a -> Label m a -> m bSource
Change the value passed to a previously captured continuation.
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 exception is Id
which is not a monad transformer
but an ordinary monad, and so, its run operation simply
eliminates the monad.)
runReaderT :: i -> ReaderT i m a -> m aSource
Execute a reader computation in the given context.
runWriterT :: 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
runContT :: (a -> m i) -> ContT i m a -> m iSource
Execute a computation with the given continuation.
Nested Execution
The following classes define operations that are overloaded
versions of the run
operations. Unlike the run
operations,
functions do not change the type of the computation (i.e, they
do not remove a layer). However, they do not perform any
side-effects in the corresponding layer. Instead, they execute
a computation in a ``separate thread'' with respect to the
corresponding effect.
class ReaderM m i => RunReaderM m i | m -> i whereSource
Classifies monads that support changing the context for a sub-computation.
RunReaderM (Reader i) i | |
RunReaderM m j => RunReaderM (ExceptionT i m) j | |
RunReaderM m j => RunReaderM (StateT i m) j | |
(RunReaderM m j, Monoid i) => RunReaderM (WriterT i m) j | |
Monad m => RunReaderM (ReaderT i m) i |
class WriterM m i => RunWriterM m i | m -> i whereSource
Classifies monads that support collecting the output of a sub-computation.
Monoid i => RunWriterM (Writer i) i | |
RunWriterM m j => RunWriterM (ExceptionT i m) j | |
RunWriterM m j => RunWriterM (StateT i m) j | |
(Monad m, Monoid i) => RunWriterM (WriterT i m) i | |
RunWriterM m j => RunWriterM (ReaderT i m) j |
class StateM m i => RunStateM m i | m -> i whereSource
Classifies monads that support separate state threads.
class ExceptionM m i => RunExceptionM m i | m -> i whereSource
Classifies monads that support handling of exceptions.
RunExceptionM (Exception i) i | |
Monad m => RunExceptionM (ExceptionT i m) i | |
RunExceptionM m i => RunExceptionM (StateT j m) i | |
(RunExceptionM m i, Monoid j) => RunExceptionM (WriterT j m) i | |
RunExceptionM m i => RunExceptionM (ReaderT j m) i |
Miscellaneous
module Control.Monad