-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Monad classes, using functional dependencies
°5u
°5uMonad classes using functional dependencies, with instances for
°5uvarious monad transformers, inspired by the paper <i>Functional
°5uProgramming with Overloading and Higher-Order Polymorphism</i>, by
°5uMark P Jones, in <i>Advanced School of Functional Programming</i>,
°5u1995 (<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>).
@package mtl
@version 2.2.2


-- | <ul>
°5u<li><i>Computation type:</i> Computations which can be interrupted and
°5uresumed.</li>
°5u<li><i>Binding strategy:</i> Binding a function to a monadic value
°5ucreates a new continuation which uses the function as the continuation
°5uof the monadic computation.</li>
°5u<li><i>Useful for:</i> Complex control structures, error handling, and
°5ucreating co-routines.</li>
°5u<li><i>Zero and plus:</i> None.</li>
°5u<li><i>Example type:</i> <tt><tt>Cont</tt> r a</tt></li>
°5u</ul>
°5u
°5uThe Continuation monad represents computations in continuation-passing
°5ustyle (CPS). In continuation-passing style function result is not
°5ureturned, but instead is passed to another function, received as a
°5uparameter (continuation). Computations are built up from sequences of
°5unested continuations, terminated by a final continuation (often
°5u<tt>id</tt>) which produces the final result. Since continuations are
°5ufunctions which represent the future of a computation, manipulation of
°5uthe continuation functions can achieve complex manipulations of the
°5ufuture of the computation, such as interrupting a computation in the
°5umiddle, aborting a portion of a computation, restarting a computation,
°5uand interleaving execution of computations. The Continuation monad
°5uadapts CPS to the structure of a monad.
°5u
°5uBefore using the Continuation monad, be sure that you have a firm
°5uunderstanding of continuation-passing style and that continuations
°5urepresent the best solution to your particular design problem. Many
°5ualgorithms which require continuations in other languages do not
°5urequire them in Haskell, due to Haskell's lazy semantics. Abuse of the
°5uContinuation monad can produce code that is impossible to understand
°5uand maintain.
module Control.Monad.Cont.Class
class Monad m => MonadCont m

-- | <tt>callCC</tt> (call-with-current-continuation) calls a function with
°5uthe current continuation as its argument. Provides an escape
°5ucontinuation mechanism for use with Continuation monads. Escape
°5ucontinuations allow to abort the current computation and return a
°5uvalue immediately. They achieve a similar effect to <a>throwError</a>
°5uand <a>catchError</a> within an <a>Error</a> monad. Advantage of this
°5ufunction over calling <tt>return</tt> is that it makes the
°5ucontinuation explicit, allowing more flexibility and better control
°5u(see examples in <a>Control.Monad.Cont</a>).
°5u
°5uThe standard idiom used with <tt>callCC</tt> is to provide a
°5ulambda-expression to name the continuation. Then calling the named
°5ucontinuation anywhere within its scope will escape from the
°5ucomputation, even if it is many layers deep within nested
°5ucomputations.
callCC :: MonadCont m => ((a -> m b) -> m a) -> m a
instance Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Cont.ContT r m)
instance (Control.Monad.Trans.Error.Error e, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Error.ErrorT e m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.List.ListT m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Maybe.MaybeT m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monoid w, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monoid w, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monoid w, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, Control.Monad.Cont.Class.MonadCont m) => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Writer.Strict.WriterT w m)


-- | <ul>
°5u<li><i>Computation type:</i> Computations which may fail or throw
°5uexceptions.</li>
°5u<li><i>Binding strategy:</i> Failure records information about the
°5ucause/location of the failure. Failure values bypass the bound
°5ufunction, other values are used as inputs to the bound function.</li>
°5u<li><i>Useful for:</i> Building computations from sequences of
°5ufunctions that may fail or using exception handling to structure error
°5uhandling.</li>
°5u<li><i>Zero and plus:</i> Zero is represented by an empty error and
°5uthe plus operation executes its second argument if the first
°5ufails.</li>
°5u<li><i>Example type:</i> <tt><a>Either</a> <tt>String</tt> a</tt></li>
°5u</ul>
°5u
°5uThe Error monad (also called the Exception monad).
module Control.Monad.Error.Class

-- | An exception to be thrown.
°5u
°5uMinimal complete definition: <a>noMsg</a> or <a>strMsg</a>.
class Error a

-- | Creates an exception without a message. The default implementation is
°5u<tt><a>strMsg</a> ""</tt>.
noMsg :: Error a => a

-- | Creates an exception with a message. The default implementation of
°5u<tt><a>strMsg</a> s</tt> is <a>noMsg</a>.
strMsg :: Error a => String -> a

-- | The strategy of combining computations that can throw exceptions by
°5ubypassing bound functions from the point an exception is thrown to the
°5upoint that it is handled.
°5u
°5uIs parameterized over the type of error information and the monad type
°5uconstructor. It is common to use <tt><a>Either</a> String</tt> as the
°5umonad type constructor for an error monad in which error descriptions
°5utake the form of strings. In that case and many other common cases the
°5uresulting monad is already defined as an instance of the
°5u<a>MonadError</a> class. You can also define your own error type
°5uand/or use a monad type constructor other than <tt><a>Either</a>
°5u<tt>String</tt></tt> or <tt><a>Either</a> <tt>IOError</tt></tt>. In
°5uthese cases you will have to explicitly define instances of the
°5u<a>MonadError</a> class. (If you are using the deprecated
°5u<a>Control.Monad.Error</a> or <a>Control.Monad.Trans.Error</a>, you
°5umay also have to define an <a>Error</a> instance.)
class (Monad m) => MonadError e m | m -> e

-- | Is used within a monadic computation to begin exception processing.
throwError :: MonadError e m => e -> m a

-- | A handler function to handle previous errors and return to normal
°5uexecution. A common idiom is:
°5u
°5u<pre>
°5udo { action1; action2; action3 } `catchError` handler
°5u</pre>
°5u
°5uwhere the <tt>action</tt> functions can call <a>throwError</a>. Note
°5uthat <tt>handler</tt> and the do-block must have the same return type.
catchError :: MonadError e m => m a -> (e -> m a) -> m a
instance Control.Monad.Error.Class.MonadError GHC.IO.Exception.IOException GHC.Types.IO
instance Control.Monad.Error.Class.MonadError e (Data.Either.Either e)
instance (GHC.Base.Monad m, Control.Monad.Trans.Error.Error e) => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Error.ErrorT e m)
instance GHC.Base.Monad m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.List.ListT m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Maybe.MaybeT m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monoid w, Control.Monad.Error.Class.MonadError e m) => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monoid w, Control.Monad.Error.Class.MonadError e m) => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monoid w, Control.Monad.Error.Class.MonadError e m) => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, Control.Monad.Error.Class.MonadError e m) => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Writer.Strict.WriterT w m)


-- | <ul>
°5u<li><i>Computation type:</i> Simple function application.</li>
°5u<li><i>Binding strategy:</i> The bound function is applied to the
°5uinput value. <tt><a>Identity</a> x &gt;&gt;= f == f x</tt></li>
°5u<li><i>Useful for:</i> Monads can be derived from monad transformers
°5uapplied to the <a>Identity</a> monad.</li>
°5u<li><i>Zero and plus:</i> None.</li>
°5u<li><i>Example type:</i> <tt><a>Identity</a> a</tt></li>
°5u</ul>
°5u
°5uThe <tt>Identity</tt> monad is a monad that does not embody any
°5ucomputational strategy. It simply applies the bound function to its
°5uinput without any modification. Computationally, there is no reason to
°5uuse the <tt>Identity</tt> monad instead of the much simpler act of
°5usimply applying functions to their arguments. The purpose of the
°5u<tt>Identity</tt> monad is its fundamental role in the theory of monad
°5utransformers. Any monad transformer applied to the <tt>Identity</tt>
°5umonad yields a non-transformer version of that monad.
module Control.Monad.Identity


-- | <ul>
°5u<li><i>Computation type:</i> Computations which read values from a
°5ushared environment.</li>
°5u<li><i>Binding strategy:</i> Monad values are functions from the
°5uenvironment to a value. The bound function is applied to the bound
°5uvalue, and both have access to the shared environment.</li>
°5u<li><i>Useful for:</i> Maintaining variable bindings, or other shared
°5uenvironment.</li>
°5u<li><i>Zero and plus:</i> None.</li>
°5u<li><i>Example type:</i> <tt><tt>Reader</tt> [(String,Value)]
°5ua</tt></li>
°5u</ul>
°5u
°5uThe <tt>Reader</tt> monad (also called the Environment monad).
°5uRepresents a computation, which can read values from a shared
°5uenvironment, pass values from function to function, and execute
°5usub-computations in a modified environment. Using <tt>Reader</tt>
°5umonad for such computations is often clearer and easier than using the
°5u<a>State</a> monad.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.Reader.Class

-- | See examples in <a>Control.Monad.Reader</a>. Note, the partially
°5uapplied function type <tt>(-&gt;) r</tt> is a simple reader monad. See
°5uthe <tt>instance</tt> declaration below.
class Monad m => MonadReader r m | m -> r

-- | Retrieves the monad environment.
ask :: MonadReader r m => m r

-- | Executes a computation in a modified environment.
local :: MonadReader r m => (r -> r) -> m a -> m a

-- | Retrieves a function of the current environment.
reader :: MonadReader r m => (r -> a) -> m a

-- | Retrieves a function of the current environment.
asks :: MonadReader r m => (r -> a) -> m a
instance Control.Monad.Reader.Class.MonadReader r ((->) r)
instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Control.Monad.Reader.Class.MonadReader r' m => Control.Monad.Reader.Class.MonadReader r' (Control.Monad.Trans.Cont.ContT r m)
instance (Control.Monad.Trans.Error.Error e, Control.Monad.Reader.Class.MonadReader r m) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Error.ErrorT e m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.List.ListT m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Maybe.MaybeT m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monoid w, Control.Monad.Reader.Class.MonadReader r m) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, Control.Monad.Reader.Class.MonadReader r m) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Writer.Strict.WriterT w m)


-- | MonadState class.
°5u
°5uThis module is inspired by the paper <i>Functional Programming with
°5uOverloading and Higher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.State.Class

-- | Minimal definition is either both of <tt>get</tt> and <tt>put</tt> or
°5ujust <tt>state</tt>
class Monad m => MonadState s m | m -> s

-- | Return the state from the internals of the monad.
get :: MonadState s m => m s

-- | Replace the state inside the monad.
put :: MonadState s m => s -> m ()

-- | Embed a simple state action into the monad.
state :: MonadState s m => (s -> (a, s)) -> m a

-- | Monadic state transformer.
°5u
°5uMaps an old state to a new state inside a state monad. The old state
°5uis thrown away.
°5u
°5u<pre>
°5uMain&gt; :t modify ((+1) :: Int -&gt; Int)
°5umodify (...) :: (MonadState Int a) =&gt; a ()
°5u</pre>
°5u
°5uThis says that <tt>modify (+1)</tt> acts over any Monad that is a
°5umember of the <tt>MonadState</tt> class, with an <tt>Int</tt> state.
modify :: MonadState s m => (s -> s) -> m ()

-- | A variant of <a>modify</a> in which the computation is strict in the
°5unew state.
modify' :: MonadState s m => (s -> s) -> m ()

-- | Gets specific component of the state, using a projection function
°5usupplied.
gets :: MonadState s m => (s -> a) -> m a
instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.State.Lazy.StateT s m)
instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Cont.ContT r m)
instance (Control.Monad.Trans.Error.Error e, Control.Monad.State.Class.MonadState s m) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Error.ErrorT e m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.List.ListT m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Maybe.MaybeT m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monoid w, Control.Monad.State.Class.MonadState s m) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, Control.Monad.State.Class.MonadState s m) => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Writer.Strict.WriterT w m)


-- | Classes for monad transformers.
°5u
°5uA monad transformer makes new monad out of an existing monad, such
°5uthat computations of the old monad may be embedded in the new one. To
°5uconstruct a monad with a desired set of features, one typically starts
°5uwith a base monad, such as <tt>Identity</tt>, <tt>[]</tt> or
°5u<a>IO</a>, and applies a sequence of monad transformers.
°5u
°5uMost monad transformer modules include the special case of applying
°5uthe transformer to <tt>Identity</tt>. For example, <tt>State s</tt> is
°5uan abbreviation for <tt>StateT s Identity</tt>.
°5u
°5uEach monad transformer also comes with an operation
°5u<tt>run</tt><i>XXX</i> to unwrap the transformer, exposing a
°5ucomputation of the inner monad.
module Control.Monad.Trans


-- | Strict state monads.
°5u
°5uThis module is inspired by the paper <i>Functional Programming with
°5uOverloading and Higher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.State.Strict

-- | Minimal definition is either both of <tt>get</tt> and <tt>put</tt> or
°5ujust <tt>state</tt>
class Monad m => MonadState s m | m -> s

-- | Return the state from the internals of the monad.
get :: MonadState s m => m s

-- | Replace the state inside the monad.
put :: MonadState s m => s -> m ()

-- | Embed a simple state action into the monad.
state :: MonadState s m => (s -> (a, s)) -> m a

-- | Monadic state transformer.
°5u
°5uMaps an old state to a new state inside a state monad. The old state
°5uis thrown away.
°5u
°5u<pre>
°5uMain&gt; :t modify ((+1) :: Int -&gt; Int)
°5umodify (...) :: (MonadState Int a) =&gt; a ()
°5u</pre>
°5u
°5uThis says that <tt>modify (+1)</tt> acts over any Monad that is a
°5umember of the <tt>MonadState</tt> class, with an <tt>Int</tt> state.
modify :: MonadState s m => (s -> s) -> m ()

-- | A variant of <a>modify</a> in which the computation is strict in the
°5unew state.
modify' :: MonadState s m => (s -> s) -> m ()

-- | Gets specific component of the state, using a projection function
°5usupplied.
gets :: MonadState s m => (s -> a) -> m a

-- | A state monad parameterized by the type <tt>s</tt> of the state to
°5ucarry.
°5u
°5uThe <a>return</a> function leaves the state unchanged, while
°5u<tt>&gt;&gt;=</tt> uses the final state of the first computation as
°5uthe initial state of the second.
type State s = StateT s Identity

-- | Unwrap a state monad computation as a function. (The inverse of
°5u<a>state</a>.)
runState :: () => State s a -> s -> (a, s)

-- | Evaluate a state computation with the given initial state and return
°5uthe final value, discarding the final state.
°5u
°5u<ul>
°5u<li><pre><a>evalState</a> m s = <a>fst</a> (<a>runState</a> m
°5us)</pre></li>
°5u</ul>
evalState :: () => State s a -> s -> a

-- | Evaluate a state computation with the given initial state and return
°5uthe final state, discarding the final value.
°5u
°5u<ul>
°5u<li><pre><a>execState</a> m s = <a>snd</a> (<a>runState</a> m
°5us)</pre></li>
°5u</ul>
execState :: () => State s a -> s -> s

-- | Map both the return value and final state of a computation using the
°5ugiven function.
°5u
°5u<ul>
°5u<li><pre><a>runState</a> (<a>mapState</a> f m) = f . <a>runState</a>
°5um</pre></li>
°5u</ul>
mapState :: () => (a, s) -> (b, s) -> State s a -> State s b

-- | <tt><a>withState</a> f m</tt> executes action <tt>m</tt> on a state
°5umodified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>withState</a> f m = <a>modify</a> f &gt;&gt; m</pre></li>
°5u</ul>
withState :: () => s -> s -> State s a -> State s a

-- | A state transformer monad parameterized by:
°5u
°5u<ul>
°5u<li><tt>s</tt> - The state.</li>
°5u<li><tt>m</tt> - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function leaves the state unchanged, while
°5u<tt>&gt;&gt;=</tt> uses the final state of the first computation as
°5uthe initial state of the second.
newtype StateT s (m :: * -> *) a
StateT :: s -> m (a, s) -> StateT s a
runStateT :: StateT s m a -> s -> m (a, s)

-- | Evaluate a state computation with the given initial state and return
°5uthe final value, discarding the final state.
°5u
°5u<ul>
°5u<li><pre><a>evalStateT</a> m s = <a>liftM</a> <a>fst</a>
°5u(<a>runStateT</a> m s)</pre></li>
°5u</ul>
evalStateT :: Monad m => StateT s m a -> s -> m a

-- | Evaluate a state computation with the given initial state and return
°5uthe final state, discarding the final value.
°5u
°5u<ul>
°5u<li><pre><a>execStateT</a> m s = <a>liftM</a> <a>snd</a>
°5u(<a>runStateT</a> m s)</pre></li>
°5u</ul>
execStateT :: Monad m => StateT s m a -> s -> m s

-- | Map both the return value and final state of a computation using the
°5ugiven function.
°5u
°5u<ul>
°5u<li><pre><a>runStateT</a> (<a>mapStateT</a> f m) = f .
°5u<a>runStateT</a> m</pre></li>
°5u</ul>
mapStateT :: () => m (a, s) -> n (b, s) -> StateT s m a -> StateT s n b

-- | <tt><a>withStateT</a> f m</tt> executes action <tt>m</tt> on a state
°5umodified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>withStateT</a> f m = <a>modify</a> f &gt;&gt; m</pre></li>
°5u</ul>
withStateT :: () => s -> s -> StateT s m a -> StateT s m a


-- | Lazy state monads.
°5u
°5uThis module is inspired by the paper <i>Functional Programming with
°5uOverloading and Higher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.State.Lazy

-- | Minimal definition is either both of <tt>get</tt> and <tt>put</tt> or
°5ujust <tt>state</tt>
class Monad m => MonadState s m | m -> s

-- | Return the state from the internals of the monad.
get :: MonadState s m => m s

-- | Replace the state inside the monad.
put :: MonadState s m => s -> m ()

-- | Embed a simple state action into the monad.
state :: MonadState s m => (s -> (a, s)) -> m a

-- | Monadic state transformer.
°5u
°5uMaps an old state to a new state inside a state monad. The old state
°5uis thrown away.
°5u
°5u<pre>
°5uMain&gt; :t modify ((+1) :: Int -&gt; Int)
°5umodify (...) :: (MonadState Int a) =&gt; a ()
°5u</pre>
°5u
°5uThis says that <tt>modify (+1)</tt> acts over any Monad that is a
°5umember of the <tt>MonadState</tt> class, with an <tt>Int</tt> state.
modify :: MonadState s m => (s -> s) -> m ()

-- | A variant of <a>modify</a> in which the computation is strict in the
°5unew state.
modify' :: MonadState s m => (s -> s) -> m ()

-- | Gets specific component of the state, using a projection function
°5usupplied.
gets :: MonadState s m => (s -> a) -> m a

-- | A state monad parameterized by the type <tt>s</tt> of the state to
°5ucarry.
°5u
°5uThe <a>return</a> function leaves the state unchanged, while
°5u<tt>&gt;&gt;=</tt> uses the final state of the first computation as
°5uthe initial state of the second.
type State s = StateT s Identity

-- | Unwrap a state monad computation as a function. (The inverse of
°5u<a>state</a>.)
runState :: () => State s a -> s -> (a, s)

-- | Evaluate a state computation with the given initial state and return
°5uthe final value, discarding the final state.
°5u
°5u<ul>
°5u<li><pre><a>evalState</a> m s = <a>fst</a> (<a>runState</a> m
°5us)</pre></li>
°5u</ul>
evalState :: () => State s a -> s -> a

-- | Evaluate a state computation with the given initial state and return
°5uthe final state, discarding the final value.
°5u
°5u<ul>
°5u<li><pre><a>execState</a> m s = <a>snd</a> (<a>runState</a> m
°5us)</pre></li>
°5u</ul>
execState :: () => State s a -> s -> s

-- | Map both the return value and final state of a computation using the
°5ugiven function.
°5u
°5u<ul>
°5u<li><pre><a>runState</a> (<a>mapState</a> f m) = f . <a>runState</a>
°5um</pre></li>
°5u</ul>
mapState :: () => (a, s) -> (b, s) -> State s a -> State s b

-- | <tt><a>withState</a> f m</tt> executes action <tt>m</tt> on a state
°5umodified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>withState</a> f m = <a>modify</a> f &gt;&gt; m</pre></li>
°5u</ul>
withState :: () => s -> s -> State s a -> State s a

-- | A state transformer monad parameterized by:
°5u
°5u<ul>
°5u<li><tt>s</tt> - The state.</li>
°5u<li><tt>m</tt> - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function leaves the state unchanged, while
°5u<tt>&gt;&gt;=</tt> uses the final state of the first computation as
°5uthe initial state of the second.
newtype StateT s (m :: * -> *) a
StateT :: s -> m (a, s) -> StateT s a
runStateT :: StateT s m a -> s -> m (a, s)

-- | Evaluate a state computation with the given initial state and return
°5uthe final value, discarding the final state.
°5u
°5u<ul>
°5u<li><pre><a>evalStateT</a> m s = <a>liftM</a> <a>fst</a>
°5u(<a>runStateT</a> m s)</pre></li>
°5u</ul>
evalStateT :: Monad m => StateT s m a -> s -> m a

-- | Evaluate a state computation with the given initial state and return
°5uthe final state, discarding the final value.
°5u
°5u<ul>
°5u<li><pre><a>execStateT</a> m s = <a>liftM</a> <a>snd</a>
°5u(<a>runStateT</a> m s)</pre></li>
°5u</ul>
execStateT :: Monad m => StateT s m a -> s -> m s

-- | Map both the return value and final state of a computation using the
°5ugiven function.
°5u
°5u<ul>
°5u<li><pre><a>runStateT</a> (<a>mapStateT</a> f m) = f .
°5u<a>runStateT</a> m</pre></li>
°5u</ul>
mapStateT :: () => m (a, s) -> n (b, s) -> StateT s m a -> StateT s n b

-- | <tt><a>withStateT</a> f m</tt> executes action <tt>m</tt> on a state
°5umodified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>withStateT</a> f m = <a>modify</a> f &gt;&gt; m</pre></li>
°5u</ul>
withStateT :: () => s -> s -> StateT s m a -> StateT s m a


-- | State monads.
°5u
°5uThis module is inspired by the paper <i>Functional Programming with
°5uOverloading and Higher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.State


-- | <ul>
°5u<li><i>Computation type:</i> Computations which read values from a
°5ushared environment.</li>
°5u<li><i>Binding strategy:</i> Monad values are functions from the
°5uenvironment to a value. The bound function is applied to the bound
°5uvalue, and both have access to the shared environment.</li>
°5u<li><i>Useful for:</i> Maintaining variable bindings, or other shared
°5uenvironment.</li>
°5u<li><i>Zero and plus:</i> None.</li>
°5u<li><i>Example type:</i> <tt><a>Reader</a> [(String,Value)]
°5ua</tt></li>
°5u</ul>
°5u
°5uThe <a>Reader</a> monad (also called the Environment monad).
°5uRepresents a computation, which can read values from a shared
°5uenvironment, pass values from function to function, and execute
°5usub-computations in a modified environment. Using <a>Reader</a> monad
°5ufor such computations is often clearer and easier than using the
°5u<a>State</a> monad.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.Reader

-- | See examples in <a>Control.Monad.Reader</a>. Note, the partially
°5uapplied function type <tt>(-&gt;) r</tt> is a simple reader monad. See
°5uthe <tt>instance</tt> declaration below.
class Monad m => MonadReader r m | m -> r

-- | Retrieves the monad environment.
ask :: MonadReader r m => m r

-- | Executes a computation in a modified environment.
local :: MonadReader r m => (r -> r) -> m a -> m a

-- | Retrieves a function of the current environment.
reader :: MonadReader r m => (r -> a) -> m a

-- | Retrieves a function of the current environment.
asks :: MonadReader r m => (r -> a) -> m a

-- | The parameterizable reader monad.
°5u
°5uComputations are functions of a shared environment.
°5u
°5uThe <a>return</a> function ignores the environment, while
°5u<tt>&gt;&gt;=</tt> passes the inherited environment to both
°5usubcomputations.
type Reader r = ReaderT r Identity

-- | Runs a <tt>Reader</tt> and extracts the final value from it. (The
°5uinverse of <a>reader</a>.)
runReader :: () => Reader r a -> r -> a

-- | Transform the value returned by a <tt>Reader</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runReader</a> (<a>mapReader</a> f m) = f .
°5u<a>runReader</a> m</pre></li>
°5u</ul>
mapReader :: () => a -> b -> Reader r a -> Reader r b

-- | Execute a computation in a modified environment (a specialization of
°5u<a>withReaderT</a>).
°5u
°5u<ul>
°5u<li><pre><a>runReader</a> (<a>withReader</a> f m) = <a>runReader</a> m
°5u. f</pre></li>
°5u</ul>
withReader :: () => r' -> r -> Reader r a -> Reader r' a

-- | The reader monad transformer, which adds a read-only environment to
°5uthe given monad.
°5u
°5uThe <a>return</a> function ignores the environment, while
°5u<tt>&gt;&gt;=</tt> passes the inherited environment to both
°5usubcomputations.
newtype ReaderT r (m :: k -> *) (a :: k) :: forall k. () => * -> k -> * -> k -> *
ReaderT :: r -> m a -> ReaderT r
runReaderT :: ReaderT r m a -> r -> m a

-- | Transform the computation inside a <tt>ReaderT</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runReaderT</a> (<a>mapReaderT</a> f m) = f .
°5u<a>runReaderT</a> m</pre></li>
°5u</ul>
mapReaderT :: () => m a -> n b -> ReaderT r m a -> ReaderT r n b

-- | Execute a computation in a modified environment (a more general
°5uversion of <a>local</a>).
°5u
°5u<ul>
°5u<li><pre><a>runReaderT</a> (<a>withReaderT</a> f m) =
°5u<a>runReaderT</a> m . f</pre></li>
°5u</ul>
withReaderT :: () => r' -> r -> ReaderT r m a -> ReaderT r' m a


-- | The List monad.
module Control.Monad.List

-- | Parameterizable list monad, with an inner monad.
°5u
°5u<i>Note:</i> this does not yield a monad unless the argument monad is
°5ucommutative.
newtype ListT (m :: * -> *) a
ListT :: m [a] -> ListT a
[runListT] :: ListT a -> m [a]

-- | Map between <a>ListT</a> computations.
°5u
°5u<ul>
°5u<li><pre><a>runListT</a> (<a>mapListT</a> f m) = f (<a>runListT</a>
°5um)</pre></li>
°5u</ul>
mapListT :: () => m [a] -> n [b] -> ListT m a -> ListT n b


-- | <ul>
°5u<li><i>Computation type:</i> Computations which may fail or throw
°5uexceptions.</li>
°5u<li><i>Binding strategy:</i> Failure records information about the
°5ucause/location of the failure. Failure values bypass the bound
°5ufunction, other values are used as inputs to the bound function.</li>
°5u<li><i>Useful for:</i> Building computations from sequences of
°5ufunctions that may fail or using exception handling to structure error
°5uhandling.</li>
°5u<li><i>Example type:</i> <tt><a>Either</a> String a</tt></li>
°5u</ul>
°5u
°5uThe Error monad (also called the Exception monad).
module Control.Monad.Except

-- | The strategy of combining computations that can throw exceptions by
°5ubypassing bound functions from the point an exception is thrown to the
°5upoint that it is handled.
°5u
°5uIs parameterized over the type of error information and the monad type
°5uconstructor. It is common to use <tt><a>Either</a> String</tt> as the
°5umonad type constructor for an error monad in which error descriptions
°5utake the form of strings. In that case and many other common cases the
°5uresulting monad is already defined as an instance of the
°5u<a>MonadError</a> class. You can also define your own error type
°5uand/or use a monad type constructor other than <tt><a>Either</a>
°5u<tt>String</tt></tt> or <tt><a>Either</a> <tt>IOError</tt></tt>. In
°5uthese cases you will have to explicitly define instances of the
°5u<a>MonadError</a> class. (If you are using the deprecated
°5u<a>Control.Monad.Error</a> or <a>Control.Monad.Trans.Error</a>, you
°5umay also have to define an <a>Error</a> instance.)
class (Monad m) => MonadError e m | m -> e

-- | Is used within a monadic computation to begin exception processing.
throwError :: MonadError e m => e -> m a

-- | A handler function to handle previous errors and return to normal
°5uexecution. A common idiom is:
°5u
°5u<pre>
°5udo { action1; action2; action3 } `catchError` handler
°5u</pre>
°5u
°5uwhere the <tt>action</tt> functions can call <a>throwError</a>. Note
°5uthat <tt>handler</tt> and the do-block must have the same return type.
catchError :: MonadError e m => m a -> (e -> m a) -> m a

-- | A monad transformer that adds exceptions to other monads.
°5u
°5u<tt>ExceptT</tt> constructs a monad parameterized over two things:
°5u
°5u<ul>
°5u<li>e - The exception type.</li>
°5u<li>m - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function yields a computation that produces the
°5ugiven value, while <tt>&gt;&gt;=</tt> sequences two subcomputations,
°5uexiting on the first exception.
newtype ExceptT e (m :: * -> *) a
ExceptT :: m Either e a -> ExceptT e a

-- | The parameterizable exception monad.
°5u
°5uComputations are either exceptions or normal values.
°5u
°5uThe <a>return</a> function returns a normal value, while
°5u<tt>&gt;&gt;=</tt> exits on the first exception. For a variant that
°5ucontinues after an error and collects all the errors, see
°5u<a>Errors</a>.
type Except e = ExceptT e Identity

-- | The inverse of <a>ExceptT</a>.
runExceptT :: () => ExceptT e m a -> m Either e a

-- | Map the unwrapped computation using the given function.
°5u
°5u<ul>
°5u<li><pre><a>runExceptT</a> (<a>mapExceptT</a> f m) = f
°5u(<a>runExceptT</a> m)</pre></li>
°5u</ul>
mapExceptT :: () => m Either e a -> n Either e' b -> ExceptT e m a -> ExceptT e' n b

-- | Transform any exceptions thrown by the computation using the given
°5ufunction.
withExceptT :: Functor m => e -> e' -> ExceptT e m a -> ExceptT e' m a

-- | Extractor for computations in the exception monad. (The inverse of
°5u<a>except</a>).
runExcept :: () => Except e a -> Either e a

-- | Map the unwrapped computation using the given function.
°5u
°5u<ul>
°5u<li><pre><a>runExcept</a> (<a>mapExcept</a> f m) = f (<a>runExcept</a>
°5um)</pre></li>
°5u</ul>
mapExcept :: () => Either e a -> Either e' b -> Except e a -> Except e' b

-- | Transform any exceptions thrown by the computation using the given
°5ufunction (a specialization of <a>withExceptT</a>).
withExcept :: () => e -> e' -> Except e a -> Except e' a


-- | <ul>
°5u<li><i>Computation type:</i> Computations which may fail or throw
°5uexceptions.</li>
°5u<li><i>Binding strategy:</i> Failure records information about the
°5ucause/location of the failure. Failure values bypass the bound
°5ufunction, other values are used as inputs to the bound function.</li>
°5u<li><i>Useful for:</i> Building computations from sequences of
°5ufunctions that may fail or using exception handling to structure error
°5uhandling.</li>
°5u<li><i>Zero and plus:</i> Zero is represented by an empty error and
°5uthe plus operation executes its second argument if the first
°5ufails.</li>
°5u<li><i>Example type:</i> <tt><a>Either</a> String a</tt></li>
°5u</ul>
°5u
°5uThe Error monad (also called the Exception monad).

-- | <i>Deprecated: Use Control.Monad.Except instead</i>
module Control.Monad.Error

-- | The strategy of combining computations that can throw exceptions by
°5ubypassing bound functions from the point an exception is thrown to the
°5upoint that it is handled.
°5u
°5uIs parameterized over the type of error information and the monad type
°5uconstructor. It is common to use <tt><a>Either</a> String</tt> as the
°5umonad type constructor for an error monad in which error descriptions
°5utake the form of strings. In that case and many other common cases the
°5uresulting monad is already defined as an instance of the
°5u<a>MonadError</a> class. You can also define your own error type
°5uand/or use a monad type constructor other than <tt><a>Either</a>
°5u<tt>String</tt></tt> or <tt><a>Either</a> <tt>IOError</tt></tt>. In
°5uthese cases you will have to explicitly define instances of the
°5u<a>MonadError</a> class. (If you are using the deprecated
°5u<a>Control.Monad.Error</a> or <a>Control.Monad.Trans.Error</a>, you
°5umay also have to define an <a>Error</a> instance.)
class (Monad m) => MonadError e m | m -> e

-- | Is used within a monadic computation to begin exception processing.
throwError :: MonadError e m => e -> m a

-- | A handler function to handle previous errors and return to normal
°5uexecution. A common idiom is:
°5u
°5u<pre>
°5udo { action1; action2; action3 } `catchError` handler
°5u</pre>
°5u
°5uwhere the <tt>action</tt> functions can call <a>throwError</a>. Note
°5uthat <tt>handler</tt> and the do-block must have the same return type.
catchError :: MonadError e m => m a -> (e -> m a) -> m a

-- | An exception to be thrown.
°5u
°5uMinimal complete definition: <a>noMsg</a> or <a>strMsg</a>.
class Error a

-- | Creates an exception without a message. The default implementation is
°5u<tt><a>strMsg</a> ""</tt>.
noMsg :: Error a => a

-- | Creates an exception with a message. The default implementation of
°5u<tt><a>strMsg</a> s</tt> is <a>noMsg</a>.
strMsg :: Error a => String -> a

-- | The error monad transformer. It can be used to add error handling to
°5uother monads.
°5u
°5uThe <tt>ErrorT</tt> Monad structure is parameterized over two things:
°5u
°5u<ul>
°5u<li>e - The error type.</li>
°5u<li>m - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function yields a successful computation, while
°5u<tt>&gt;&gt;=</tt> sequences two subcomputations, failing on the first
°5uerror.
newtype ErrorT e (m :: * -> *) a
ErrorT :: m Either e a -> ErrorT e a
runErrorT :: ErrorT e m a -> m Either e a

-- | Map the unwrapped computation using the given function.
°5u
°5u<ul>
°5u<li><pre><a>runErrorT</a> (<a>mapErrorT</a> f m) = f (<a>runErrorT</a>
°5um)</pre></li>
°5u</ul>
mapErrorT :: () => m Either e a -> n Either e' b -> ErrorT e m a -> ErrorT e' n b


-- | <ul>
°5u<li><i>Computation type:</i> Computations which can be interrupted and
°5uresumed.</li>
°5u<li><i>Binding strategy:</i> Binding a function to a monadic value
°5ucreates a new continuation which uses the function as the continuation
°5uof the monadic computation.</li>
°5u<li><i>Useful for:</i> Complex control structures, error handling, and
°5ucreating co-routines.</li>
°5u<li><i>Zero and plus:</i> None.</li>
°5u<li><i>Example type:</i> <tt><a>Cont</a> r a</tt></li>
°5u</ul>
°5u
°5uThe Continuation monad represents computations in continuation-passing
°5ustyle (CPS). In continuation-passing style function result is not
°5ureturned, but instead is passed to another function, received as a
°5uparameter (continuation). Computations are built up from sequences of
°5unested continuations, terminated by a final continuation (often
°5u<tt>id</tt>) which produces the final result. Since continuations are
°5ufunctions which represent the future of a computation, manipulation of
°5uthe continuation functions can achieve complex manipulations of the
°5ufuture of the computation, such as interrupting a computation in the
°5umiddle, aborting a portion of a computation, restarting a computation,
°5uand interleaving execution of computations. The Continuation monad
°5uadapts CPS to the structure of a monad.
°5u
°5uBefore using the Continuation monad, be sure that you have a firm
°5uunderstanding of continuation-passing style and that continuations
°5urepresent the best solution to your particular design problem. Many
°5ualgorithms which require continuations in other languages do not
°5urequire them in Haskell, due to Haskell's lazy semantics. Abuse of the
°5uContinuation monad can produce code that is impossible to understand
°5uand maintain.
module Control.Monad.Cont
class Monad m => MonadCont m

-- | <tt>callCC</tt> (call-with-current-continuation) calls a function with
°5uthe current continuation as its argument. Provides an escape
°5ucontinuation mechanism for use with Continuation monads. Escape
°5ucontinuations allow to abort the current computation and return a
°5uvalue immediately. They achieve a similar effect to <a>throwError</a>
°5uand <a>catchError</a> within an <a>Error</a> monad. Advantage of this
°5ufunction over calling <tt>return</tt> is that it makes the
°5ucontinuation explicit, allowing more flexibility and better control
°5u(see examples in <a>Control.Monad.Cont</a>).
°5u
°5uThe standard idiom used with <tt>callCC</tt> is to provide a
°5ulambda-expression to name the continuation. Then calling the named
°5ucontinuation anywhere within its scope will escape from the
°5ucomputation, even if it is many layers deep within nested
°5ucomputations.
callCC :: MonadCont m => ((a -> m b) -> m a) -> m a

-- | Continuation monad. <tt>Cont r a</tt> is a CPS ("continuation-passing
°5ustyle") computation that produces an intermediate result of type
°5u<tt>a</tt> within a CPS computation whose final result type is
°5u<tt>r</tt>.
°5u
°5uThe <tt>return</tt> function simply creates a continuation which
°5upasses the value on.
°5u
°5uThe <tt>&gt;&gt;=</tt> operator adds the bound function into the
°5ucontinuation chain.
type Cont r = ContT r Identity

-- | Construct a continuation-passing computation from a function. (The
°5uinverse of <a>runCont</a>)
cont :: () => a -> r -> r -> Cont r a

-- | The result of running a CPS computation with a given final
°5ucontinuation. (The inverse of <a>cont</a>)
runCont :: () => Cont r a -> a -> r -> r

-- | Apply a function to transform the result of a continuation-passing
°5ucomputation.
°5u
°5u<ul>
°5u<li><pre><a>runCont</a> (<a>mapCont</a> f m) = f . <a>runCont</a>
°5um</pre></li>
°5u</ul>
mapCont :: () => r -> r -> Cont r a -> Cont r a

-- | Apply a function to transform the continuation passed to a CPS
°5ucomputation.
°5u
°5u<ul>
°5u<li><pre><a>runCont</a> (<a>withCont</a> f m) = <a>runCont</a> m .
°5uf</pre></li>
°5u</ul>
withCont :: () => b -> r -> a -> r -> Cont r a -> Cont r b

-- | The continuation monad transformer. Can be used to add continuation
°5uhandling to any type constructor: the <a>Monad</a> instance and most
°5uof the operations do not require <tt>m</tt> to be a monad.
°5u
°5u<a>ContT</a> is not a functor on the category of monads, and many
°5uoperations cannot be lifted through it.
newtype ContT (r :: k) (m :: k -> *) a :: forall k. () => k -> k -> * -> * -> *
ContT :: a -> m r -> m r -> ContT a
runContT :: ContT r m a -> a -> m r -> m r

-- | Apply a function to transform the result of a continuation-passing
°5ucomputation. This has a more restricted type than the <tt>map</tt>
°5uoperations for other monad transformers, because <a>ContT</a> does not
°5udefine a functor in the category of monads.
°5u
°5u<ul>
°5u<li><pre><a>runContT</a> (<a>mapContT</a> f m) = f . <a>runContT</a>
°5um</pre></li>
°5u</ul>
mapContT :: () => m r -> m r -> ContT r m a -> ContT r m a

-- | Apply a function to transform the continuation passed to a CPS
°5ucomputation.
°5u
°5u<ul>
°5u<li><pre><a>runContT</a> (<a>withContT</a> f m) = <a>runContT</a> m .
°5uf</pre></li>
°5u</ul>
withContT :: () => b -> m r -> a -> m r -> ContT r m a -> ContT r m b


-- | The MonadWriter class.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>) Advanced
°5uSchool of Functional Programming, 1995.
module Control.Monad.Writer.Class
class (Monoid w, Monad m) => MonadWriter w m | m -> w

-- | <tt><a>writer</a> (a,w)</tt> embeds a simple writer action.
writer :: MonadWriter w m => (a, w) -> m a

-- | <tt><a>tell</a> w</tt> is an action that produces the output
°5u<tt>w</tt>.
tell :: MonadWriter w m => w -> m ()

-- | <tt><a>listen</a> m</tt> is an action that executes the action
°5u<tt>m</tt> and adds its output to the value of the computation.
listen :: MonadWriter w m => m a -> m (a, w)

-- | <tt><a>pass</a> m</tt> is an action that executes the action
°5u<tt>m</tt>, which returns a value and a function, and returns the
°5uvalue, applying the function to the output.
pass :: MonadWriter w m => m (a, w -> w) -> m a

-- | <tt><a>listens</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and adds the result of applying <tt>f</tt> to the output to
°5uthe value of the computation.
°5u
°5u<ul>
°5u<li><pre><a>listens</a> f m = <a>liftM</a> (id *** f) (<a>listen</a>
°5um)</pre></li>
°5u</ul>
listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)

-- | <tt><a>censor</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and applies the function <tt>f</tt> to its output, leaving
°5uthe return value unchanged.
°5u
°5u<ul>
°5u<li><pre><a>censor</a> f m = <a>pass</a> (<a>liftM</a> (\x -&gt;
°5u(x,f)) m)</pre></li>
°5u</ul>
censor :: MonadWriter w m => (w -> w) -> m a -> m a
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance (Control.Monad.Trans.Error.Error e, Control.Monad.Writer.Class.MonadWriter w m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Error.ErrorT e m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Except.ExceptT e m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Maybe.MaybeT m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Reader.ReaderT r m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.State.Strict.StateT s m)


-- | Declaration of the MonadRWS class.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.RWS.Class
class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s m | m -> r, m -> w, m -> s
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Control.Monad.RWS.Class.MonadRWS r w s m => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.Except.ExceptT e m)
instance (Control.Monad.Trans.Error.Error e, Control.Monad.RWS.Class.MonadRWS r w s m) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.Error.ErrorT e m)
instance Control.Monad.RWS.Class.MonadRWS r w s m => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.Identity.IdentityT m)
instance Control.Monad.RWS.Class.MonadRWS r w s m => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.Maybe.MaybeT m)


-- | Strict RWS monad.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.RWS.Strict

-- | A monad containing an environment of type <tt>r</tt>, output of type
°5u<tt>w</tt> and an updatable state of type <tt>s</tt>.
type RWS r w s = RWST r w s Identity

-- | Construct an RWS computation from a function. (The inverse of
°5u<a>runRWS</a>.)
rws :: () => r -> s -> (a, s, w) -> RWS r w s a

-- | Unwrap an RWS computation as a function. (The inverse of <a>rws</a>.)
runRWS :: () => RWS r w s a -> r -> s -> (a, s, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final value and output, discarding the final state.
evalRWS :: () => RWS r w s a -> r -> s -> (a, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final state and output, discarding the final value.
execRWS :: () => RWS r w s a -> r -> s -> (s, w)

-- | Map the return value, final state and output of a computation using
°5uthe given function.
°5u
°5u<ul>
°5u<li><pre><a>runRWS</a> (<a>mapRWS</a> f m) r s = f (<a>runRWS</a> m r
°5us)</pre></li>
°5u</ul>
mapRWS :: () => (a, s, w) -> (b, s, w') -> RWS r w s a -> RWS r w' s b

-- | <tt><a>withRWS</a> f m</tt> executes action <tt>m</tt> with an initial
°5uenvironment and state modified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runRWS</a> (<a>withRWS</a> f m) r s = <a>uncurry</a>
°5u(<a>runRWS</a> m) (f r s)</pre></li>
°5u</ul>
withRWS :: () => r' -> s -> (r, s) -> RWS r w s a -> RWS r' w s a

-- | A monad transformer adding reading an environment of type <tt>r</tt>,
°5ucollecting an output of type <tt>w</tt> and updating a state of type
°5u<tt>s</tt> to an inner monad <tt>m</tt>.
newtype RWST r w s (m :: * -> *) a
RWST :: r -> s -> m (a, s, w) -> RWST r w s a
runRWST :: RWST r w s m a -> r -> s -> m (a, s, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final value and output, discarding the final state.
evalRWST :: Monad m => RWST r w s m a -> r -> s -> m (a, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final state and output, discarding the final value.
execRWST :: Monad m => RWST r w s m a -> r -> s -> m (s, w)

-- | Map the inner computation using the given function.
°5u
°5u<ul>
°5u<li><pre><a>runRWST</a> (<a>mapRWST</a> f m) r s = f (<a>runRWST</a> m
°5ur s)</pre></li>
°5u</ul>
mapRWST :: () => m (a, s, w) -> n (b, s, w') -> RWST r w s m a -> RWST r w' s n b

-- | <tt><a>withRWST</a> f m</tt> executes action <tt>m</tt> with an
°5uinitial environment and state modified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runRWST</a> (<a>withRWST</a> f m) r s = <a>uncurry</a>
°5u(<a>runRWST</a> m) (f r s)</pre></li>
°5u</ul>
withRWST :: () => r' -> s -> (r, s) -> RWST r w s m a -> RWST r' w s m a


-- | Lazy RWS monad.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.RWS.Lazy

-- | A monad containing an environment of type <tt>r</tt>, output of type
°5u<tt>w</tt> and an updatable state of type <tt>s</tt>.
type RWS r w s = RWST r w s Identity

-- | Construct an RWS computation from a function. (The inverse of
°5u<a>runRWS</a>.)
rws :: () => r -> s -> (a, s, w) -> RWS r w s a

-- | Unwrap an RWS computation as a function. (The inverse of <a>rws</a>.)
runRWS :: () => RWS r w s a -> r -> s -> (a, s, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final value and output, discarding the final state.
evalRWS :: () => RWS r w s a -> r -> s -> (a, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final state and output, discarding the final value.
execRWS :: () => RWS r w s a -> r -> s -> (s, w)

-- | Map the return value, final state and output of a computation using
°5uthe given function.
°5u
°5u<ul>
°5u<li><pre><a>runRWS</a> (<a>mapRWS</a> f m) r s = f (<a>runRWS</a> m r
°5us)</pre></li>
°5u</ul>
mapRWS :: () => (a, s, w) -> (b, s, w') -> RWS r w s a -> RWS r w' s b

-- | <tt><a>withRWS</a> f m</tt> executes action <tt>m</tt> with an initial
°5uenvironment and state modified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runRWS</a> (<a>withRWS</a> f m) r s = <a>uncurry</a>
°5u(<a>runRWS</a> m) (f r s)</pre></li>
°5u</ul>
withRWS :: () => r' -> s -> (r, s) -> RWS r w s a -> RWS r' w s a

-- | A monad transformer adding reading an environment of type <tt>r</tt>,
°5ucollecting an output of type <tt>w</tt> and updating a state of type
°5u<tt>s</tt> to an inner monad <tt>m</tt>.
newtype RWST r w s (m :: * -> *) a
RWST :: r -> s -> m (a, s, w) -> RWST r w s a
runRWST :: RWST r w s m a -> r -> s -> m (a, s, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final value and output, discarding the final state.
evalRWST :: Monad m => RWST r w s m a -> r -> s -> m (a, w)

-- | Evaluate a computation with the given initial state and environment,
°5ureturning the final state and output, discarding the final value.
execRWST :: Monad m => RWST r w s m a -> r -> s -> m (s, w)

-- | Map the inner computation using the given function.
°5u
°5u<ul>
°5u<li><pre><a>runRWST</a> (<a>mapRWST</a> f m) r s = f (<a>runRWST</a> m
°5ur s)</pre></li>
°5u</ul>
mapRWST :: () => m (a, s, w) -> n (b, s, w') -> RWST r w s m a -> RWST r w' s n b

-- | <tt><a>withRWST</a> f m</tt> executes action <tt>m</tt> with an
°5uinitial environment and state modified by applying <tt>f</tt>.
°5u
°5u<ul>
°5u<li><pre><a>runRWST</a> (<a>withRWST</a> f m) r s = <a>uncurry</a>
°5u(<a>runRWST</a> m) (f r s)</pre></li>
°5u</ul>
withRWST :: () => r' -> s -> (r, s) -> RWST r w s m a -> RWST r' w s m a


-- | Declaration of the MonadRWS class.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
°5uProgramming, 1995.
module Control.Monad.RWS


-- | Lazy writer monads.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>) Advanced
°5uSchool of Functional Programming, 1995.
module Control.Monad.Writer.Lazy
class (Monoid w, Monad m) => MonadWriter w m | m -> w

-- | <tt><a>writer</a> (a,w)</tt> embeds a simple writer action.
writer :: MonadWriter w m => (a, w) -> m a

-- | <tt><a>tell</a> w</tt> is an action that produces the output
°5u<tt>w</tt>.
tell :: MonadWriter w m => w -> m ()

-- | <tt><a>listen</a> m</tt> is an action that executes the action
°5u<tt>m</tt> and adds its output to the value of the computation.
listen :: MonadWriter w m => m a -> m (a, w)

-- | <tt><a>pass</a> m</tt> is an action that executes the action
°5u<tt>m</tt>, which returns a value and a function, and returns the
°5uvalue, applying the function to the output.
pass :: MonadWriter w m => m (a, w -> w) -> m a

-- | <tt><a>listens</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and adds the result of applying <tt>f</tt> to the output to
°5uthe value of the computation.
°5u
°5u<ul>
°5u<li><pre><a>listens</a> f m = <a>liftM</a> (id *** f) (<a>listen</a>
°5um)</pre></li>
°5u</ul>
listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)

-- | <tt><a>censor</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and applies the function <tt>f</tt> to its output, leaving
°5uthe return value unchanged.
°5u
°5u<ul>
°5u<li><pre><a>censor</a> f m = <a>pass</a> (<a>liftM</a> (\x -&gt;
°5u(x,f)) m)</pre></li>
°5u</ul>
censor :: MonadWriter w m => (w -> w) -> m a -> m a

-- | A writer monad parameterized by the type <tt>w</tt> of output to
°5uaccumulate.
°5u
°5uThe <a>return</a> function produces the output <a>mempty</a>, while
°5u<tt>&gt;&gt;=</tt> combines the outputs of the subcomputations using
°5u<a>mappend</a>.
type Writer w = WriterT w Identity

-- | Unwrap a writer computation as a (result, output) pair. (The inverse
°5uof <a>writer</a>.)
runWriter :: () => Writer w a -> (a, w)

-- | Extract the output from a writer computation.
°5u
°5u<ul>
°5u<li><pre><a>execWriter</a> m = <a>snd</a> (<a>runWriter</a>
°5um)</pre></li>
°5u</ul>
execWriter :: () => Writer w a -> w

-- | Map both the return value and output of a computation using the given
°5ufunction.
°5u
°5u<ul>
°5u<li><pre><a>runWriter</a> (<a>mapWriter</a> f m) = f (<a>runWriter</a>
°5um)</pre></li>
°5u</ul>
mapWriter :: () => (a, w) -> (b, w') -> Writer w a -> Writer w' b

-- | A writer monad parameterized by:
°5u
°5u<ul>
°5u<li><tt>w</tt> - the output to accumulate.</li>
°5u<li><tt>m</tt> - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function produces the output <a>mempty</a>, while
°5u<tt>&gt;&gt;=</tt> combines the outputs of the subcomputations using
°5u<a>mappend</a>.
newtype WriterT w (m :: * -> *) a
WriterT :: m (a, w) -> WriterT w a
runWriterT :: WriterT w m a -> m (a, w)

-- | Extract the output from a writer computation.
°5u
°5u<ul>
°5u<li><pre><a>execWriterT</a> m = <a>liftM</a> <a>snd</a>
°5u(<a>runWriterT</a> m)</pre></li>
°5u</ul>
execWriterT :: Monad m => WriterT w m a -> m w

-- | Map both the return value and output of a computation using the given
°5ufunction.
°5u
°5u<ul>
°5u<li><pre><a>runWriterT</a> (<a>mapWriterT</a> f m) = f
°5u(<a>runWriterT</a> m)</pre></li>
°5u</ul>
mapWriterT :: () => m (a, w) -> n (b, w') -> WriterT w m a -> WriterT w' n b


-- | The MonadWriter class.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>) Advanced
°5uSchool of Functional Programming, 1995.
module Control.Monad.Writer


-- | Strict writer monads.
°5u
°5uInspired by the paper <i>Functional Programming with Overloading and
°5uHigher-Order Polymorphism</i>, Mark P Jones
°5u(<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>) Advanced
°5uSchool of Functional Programming, 1995.
module Control.Monad.Writer.Strict
class (Monoid w, Monad m) => MonadWriter w m | m -> w

-- | <tt><a>writer</a> (a,w)</tt> embeds a simple writer action.
writer :: MonadWriter w m => (a, w) -> m a

-- | <tt><a>tell</a> w</tt> is an action that produces the output
°5u<tt>w</tt>.
tell :: MonadWriter w m => w -> m ()

-- | <tt><a>listen</a> m</tt> is an action that executes the action
°5u<tt>m</tt> and adds its output to the value of the computation.
listen :: MonadWriter w m => m a -> m (a, w)

-- | <tt><a>pass</a> m</tt> is an action that executes the action
°5u<tt>m</tt>, which returns a value and a function, and returns the
°5uvalue, applying the function to the output.
pass :: MonadWriter w m => m (a, w -> w) -> m a

-- | <tt><a>listens</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and adds the result of applying <tt>f</tt> to the output to
°5uthe value of the computation.
°5u
°5u<ul>
°5u<li><pre><a>listens</a> f m = <a>liftM</a> (id *** f) (<a>listen</a>
°5um)</pre></li>
°5u</ul>
listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)

-- | <tt><a>censor</a> f m</tt> is an action that executes the action
°5u<tt>m</tt> and applies the function <tt>f</tt> to its output, leaving
°5uthe return value unchanged.
°5u
°5u<ul>
°5u<li><pre><a>censor</a> f m = <a>pass</a> (<a>liftM</a> (\x -&gt;
°5u(x,f)) m)</pre></li>
°5u</ul>
censor :: MonadWriter w m => (w -> w) -> m a -> m a

-- | A writer monad parameterized by the type <tt>w</tt> of output to
°5uaccumulate.
°5u
°5uThe <a>return</a> function produces the output <a>mempty</a>, while
°5u<tt>&gt;&gt;=</tt> combines the outputs of the subcomputations using
°5u<a>mappend</a>.
type Writer w = WriterT w Identity

-- | Unwrap a writer computation as a (result, output) pair. (The inverse
°5uof <a>writer</a>.)
runWriter :: () => Writer w a -> (a, w)

-- | Extract the output from a writer computation.
°5u
°5u<ul>
°5u<li><pre><a>execWriter</a> m = <a>snd</a> (<a>runWriter</a>
°5um)</pre></li>
°5u</ul>
execWriter :: () => Writer w a -> w

-- | Map both the return value and output of a computation using the given
°5ufunction.
°5u
°5u<ul>
°5u<li><pre><a>runWriter</a> (<a>mapWriter</a> f m) = f (<a>runWriter</a>
°5um)</pre></li>
°5u</ul>
mapWriter :: () => (a, w) -> (b, w') -> Writer w a -> Writer w' b

-- | A writer monad parameterized by:
°5u
°5u<ul>
°5u<li><tt>w</tt> - the output to accumulate.</li>
°5u<li><tt>m</tt> - The inner monad.</li>
°5u</ul>
°5u
°5uThe <a>return</a> function produces the output <a>mempty</a>, while
°5u<tt>&gt;&gt;=</tt> combines the outputs of the subcomputations using
°5u<a>mappend</a>.
newtype WriterT w (m :: * -> *) a
WriterT :: m (a, w) -> WriterT w a
[runWriterT] :: WriterT w a -> m (a, w)

-- | Extract the output from a writer computation.
°5u
°5u<ul>
°5u<li><pre><a>execWriterT</a> m = <a>liftM</a> <a>snd</a>
°5u(<a>runWriterT</a> m)</pre></li>
°5u</ul>
execWriterT :: Monad m => WriterT w m a -> m w

-- | Map both the return value and output of a computation using the given
°5ufunction.
°5u
°5u<ul>
°5u<li><pre><a>runWriterT</a> (<a>mapWriterT</a> f m) = f
°5u(<a>runWriterT</a> m)</pre></li>
°5u</ul>
mapWriterT :: () => m (a, w) -> n (b, w') -> WriterT w m a -> WriterT w' n b
