The Monad Transformer Library
See the codemtl MTL is a collection of monad classes, extending the transformers
package, using functional dependencies for generic lifting of monadic
actions.
Transformers in MTL are divided into classes and data types. Classes
define the monadic operations of transformers. Data types, generally
from the transformers package, implement transformers, and MTL
provides instances for all the transformer type classes.
MTL and transformers use a common module, data type, and function
naming scheme. As an example, let's imagine we have a transformer
Foo.
In the Control.Monad.Foo module, we'd find:
MonadFoo with the transformer operations.FooT with instances for all monad transformer classes.runFooT. For
the actual transformers, there are usually a number of useful runner
functions.When using monad transformers, you often need to "lift" a monadic
action into your transformed monadic action. This is done using the
lift function from MonadTrans in the Control.Monad.Trans.Class
module:
lift :: (Monad m, MonadTrans t) => m a -> t m a
The action m a is lifted into the transformer action t m a.
As an example, here we lift an action of type IO a into an action of
type ExceptT MyError IO a:
data MyError = EmptyLine
mightFail :: ExceptT MyError IO ()
mightFail = do
l <- lift getLine
when (null l) (throwError EmptyLine)
The following outlines the available monad classes and transformers in
MTL and transformers. For more details, and the corresponding
documentation of the mtl version you are using, see the
documentation on Hackage.
Control.Monad.Cont
The Continuation monad transformer adds the ability to use continuation-passing style (CPS) in a monadic computation. Continuations can be used to manipulate the control flow of a program, e.g. early exit, error handling, or suspending a computation.
Control.Monad.Cont.Class.MonadContControl.Monad.Cont.ContTControl.Monad.Error (deprecated!)
The Error monad transformer has been deprecated in favor of
Control.Monad.Except.
Control.Monad.Except
The Except monad transformer adds the ability to fail with an error in a monadic computation.
Control.Monad.Except.Class.MonadErrorControl.Monad.Except.ExceptTControl.Monad.Identity
The Identity monad transformer does not add any abilities to a monad. It simply applies the bound function to its inner monad without any modification.
Control.Monad.Trans.Identity.IdentityT (in the transformers package)Data.Functor.Identity.Identity (in the base package)Control.Monad.RWS
A convenient transformer that combines the Reader, Writer, and State monad transformers.
Control.Monad.RWS.Lazy.RWST (which is the default, exported by Control.Monad.RWS)Control.Monad.RWS.Strict.RWSTControl.Monad.Reader
The Reader monad transformer represents a computation which can read values from an environment.
Control.Monad.Reader.Class.MonadReaderControl.Monad.Reader.ReaderTControl.Monad.State
The State monad transformer represents a computation which can read and write internal state values. If you only need to read values, you might want to use Reader instead.
Control.Monad.State.Class.MonadStateControl.Monad.State.Lazy.StateT (the default, exported by Control.Monad.State)Control.Monad.State.Strict.StateTControl.Monad.Writer
The Writer monad transformer represents a computation that can
produce a stream of data in addition to the computed values. This
can be used to collect values in some data structure with a
Monoid instance. This can be used for things like logging and
accumulating values throughout a computation.
Control.Monad.Writer.Class.MonadWriterControl.Monad.Writer.Lazy.WriterTControl.Monad.Writer.Strict.WriterTControl.Monad.Accum
The Accum monad transformer represents a computation which
manages append-only state, or a writer that can read all
previous inputs. It binds a function to a monadic value by
lazily accumulating subcomputations via (<>). For more general
access, use State instead.
Control.Monad.AccumControl.Monad.Trans.Accum.AccumTControl.Monad.Select
The Select monad transformer represents a computation which
can do backtracking search using a 'ranked' evaluation strategy.
Binding a function to a monad value chains together evaluation
strategies in the sense that the results of previous strategies
may influence subsequent rank and evaluation strategies in
subcomputations.
Control.Monad.SelectControl.Monad.Trans.Select.SelectTmtl on Hackage(top 30 of 44)
Haskell
100.0%
The Monad Transformer Library
See the codemtl MTL is a collection of monad classes, extending the transformers
package, using functional dependencies for generic lifting of monadic
actions.
Transformers in MTL are divided into classes and data types. Classes
define the monadic operations of transformers. Data types, generally
from the transformers package, implement transformers, and MTL
provides instances for all the transformer type classes.
MTL and transformers use a common module, data type, and function
naming scheme. As an example, let's imagine we have a transformer
Foo.
In the Control.Monad.Foo module, we'd find:
MonadFoo with the transformer operations.FooT with instances for all monad transformer classes.runFooT. For
the actual transformers, there are usually a number of useful runner
functions.When using monad transformers, you often need to "lift" a monadic
action into your transformed monadic action. This is done using the
lift function from MonadTrans in the Control.Monad.Trans.Class
module:
lift :: (Monad m, MonadTrans t) => m a -> t m a
The action m a is lifted into the transformer action t m a.
As an example, here we lift an action of type IO a into an action of
type ExceptT MyError IO a:
data MyError = EmptyLine
mightFail :: ExceptT MyError IO ()
mightFail = do
l <- lift getLine
when (null l) (throwError EmptyLine)
The following outlines the available monad classes and transformers in
MTL and transformers. For more details, and the corresponding
documentation of the mtl version you are using, see the
documentation on Hackage.
Control.Monad.Cont
The Continuation monad transformer adds the ability to use continuation-passing style (CPS) in a monadic computation. Continuations can be used to manipulate the control flow of a program, e.g. early exit, error handling, or suspending a computation.
Control.Monad.Cont.Class.MonadContControl.Monad.Cont.ContTControl.Monad.Error (deprecated!)
The Error monad transformer has been deprecated in favor of
Control.Monad.Except.
Control.Monad.Except
The Except monad transformer adds the ability to fail with an error in a monadic computation.
Control.Monad.Except.Class.MonadErrorControl.Monad.Except.ExceptTControl.Monad.Identity
The Identity monad transformer does not add any abilities to a monad. It simply applies the bound function to its inner monad without any modification.
Control.Monad.Trans.Identity.IdentityT (in the transformers package)Data.Functor.Identity.Identity (in the base package)Control.Monad.RWS
A convenient transformer that combines the Reader, Writer, and State monad transformers.
Control.Monad.RWS.Lazy.RWST (which is the default, exported by Control.Monad.RWS)Control.Monad.RWS.Strict.RWSTControl.Monad.Reader
The Reader monad transformer represents a computation which can read values from an environment.
Control.Monad.Reader.Class.MonadReaderControl.Monad.Reader.ReaderTControl.Monad.State
The State monad transformer represents a computation which can read and write internal state values. If you only need to read values, you might want to use Reader instead.
Control.Monad.State.Class.MonadStateControl.Monad.State.Lazy.StateT (the default, exported by Control.Monad.State)Control.Monad.State.Strict.StateTControl.Monad.Writer
The Writer monad transformer represents a computation that can
produce a stream of data in addition to the computed values. This
can be used to collect values in some data structure with a
Monoid instance. This can be used for things like logging and
accumulating values throughout a computation.
Control.Monad.Writer.Class.MonadWriterControl.Monad.Writer.Lazy.WriterTControl.Monad.Writer.Strict.WriterTControl.Monad.Accum
The Accum monad transformer represents a computation which
manages append-only state, or a writer that can read all
previous inputs. It binds a function to a monadic value by
lazily accumulating subcomputations via (<>). For more general
access, use State instead.
Control.Monad.AccumControl.Monad.Trans.Accum.AccumTControl.Monad.Select
The Select monad transformer represents a computation which
can do backtracking search using a 'ranked' evaluation strategy.
Binding a function to a monad value chains together evaluation
strategies in the sense that the results of previous strategies
may influence subsequent rank and evaluation strategies in
subcomputations.
Control.Monad.SelectControl.Monad.Trans.Select.SelectTmtl on Hackage(top 30 of 44)
Haskell
100.0%