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


-- | MonadWriter orphan instances for writer-cps-transformers
--   
--   The WriterT and RWST monad transformers provided by
--   writer-cps-transformers are written in continuation passing style and
--   avoid the space-leak problem of the traditional
--   Control.Monad.Trans.Writer.Strict and Control.Monad.Trans.Writer.Lazy.
--   See also
--   (<a>http://hackage.haskell.org/package/writer-cps-transformers</a>).
@package writer-cps-mtl
@version 0.1.1.4


-- | Stricter RWS monad using continuation-passing-style for the writer
--   output.
--   
--   Inspired by the paper <i>Functional Programming with Overloading and
--   Higher-Order Polymorphism</i>, Mark P Jones
--   (<a>http://web.cecs.pdx.edu/~mpj/</a>) Advanced School of Functional
--   Programming, 1995.
module Control.Monad.RWS.CPS

-- | A monad containing an environment of type <tt>r</tt>, output of type
--   <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
--   <a>runRWS</a>.)
rws :: Monoid w => r -> s -> (a, s, w) -> RWS r w s a

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

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

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

-- | Map the return value, final state and output of a computation using
--   the given function.
--   
--   <ul>
--   <li><pre><a>runRWS</a> (<a>mapRWS</a> f m) r s = f (<a>runRWS</a> m r
--   s)</pre></li>
--   </ul>
mapRWS :: (Monoid w, Monoid w') => (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
--   environment and state modified by applying <tt>f</tt>.
--   
--   <ul>
--   <li><pre><a>runRWS</a> (<a>withRWS</a> f m) r s = <a>uncurry</a>
--   (<a>runRWS</a> m) (f r s)</pre></li>
--   </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>,
--   collecting an output of type <tt>w</tt> and updating a state of type
--   <tt>s</tt> to an inner monad <tt>m</tt>.
data RWST r w s (m :: * -> *) a

-- | The RWST constructor is deliberately not exported in the CPS module to
--   avoid exposing the hidden state w. rwsT provides a safe way to
--   construct a RWST with the same api as the original RWST.
rwsT :: (Functor m, Monoid w) => r -> s -> m (a, s, w) -> RWST r w s m a

-- | Unwrap an RWST computation as a function.
runRWST :: Monoid w => RWST r w s m a -> r -> s -> m (a, s, w)

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

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

-- | Map the inner computation using the given function.
--   
--   <ul>
--   <li><tt><a>runRWST</a> (<a>mapRWST</a> f m) r s = f (<a>runRWST</a> m
--   r s)</tt> mapRWST :: (m (a, s, w) -&gt; n (b, s, w')) -&gt; RWST r w s
--   m a -&gt; RWST r w' s n b</li>
--   </ul>
mapRWST :: (Monad n, Monoid w, Monoid w') => 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
--   initial environment and state modified by applying <tt>f</tt>.
--   
--   <ul>
--   <li><pre><a>runRWST</a> (<a>withRWST</a> f m) r s = <a>uncurry</a>
--   (<a>runRWST</a> m) (f r s)</pre></li>
--   </ul>
withRWST :: () => r' -> s -> (r, s) -> RWST r w s m a -> RWST r' w s m a
instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)
instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)
instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.RWS.CPS.Internal.RWST r w s m)


-- | Stricter writer monad using continuation-passing-style for the writer
--   output.
--   
--   Inspired by the paper <i>Functional Programming with Overloading and
--   Higher-Order Polymorphism</i>, Mark P Jones
--   (<a>http://web.cecs.pdx.edu/~mpj/pubs/springschool.html</a>) Advanced
--   School of Functional Programming, 1995.
module Control.Monad.Writer.CPS

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

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

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

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

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

-- | The WriterT constructor is deliberately not exported in the CPS module
--   to avoid exposing the hidden state w. writerT provides a safe way to
--   construct a WriterT with the same api as the original WriterT.
writerT :: (Functor m, Monoid w) => m (a, w) -> WriterT w m a

-- | Unwrap a writer computation.
runWriterT :: Monoid w => WriterT w m a -> m (a, w)

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

-- | Map both the return value and output of a computation using the given
--   function.
--   
--   <ul>
--   <li><pre><a>runWriterT</a> (<a>mapWriterT</a> f m) = f
--   (<a>runWriterT</a> m)</pre></li>
--   </ul>
mapWriterT :: (Monad n, Monoid w, Monoid w') => m (a, w) -> n (b, w') -> WriterT w m a -> WriterT w' n b
instance (GHC.Base.Monad m, GHC.Base.Monoid w) => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.Trans.Writer.CPS.Internal.WriterT w m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.Trans.Writer.CPS.Internal.WriterT w m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.Trans.Writer.CPS.Internal.WriterT w m)
instance (Control.Monad.Reader.Class.MonadReader r m, GHC.Base.Monoid w) => Control.Monad.Reader.Class.MonadReader r (Control.Monad.Trans.Writer.CPS.Internal.WriterT w m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.Trans.Writer.CPS.Internal.WriterT w m)
