| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Monad.Trans.MSF.Writer
Contents
Description
MSFs with a Writer monadic layer.
This module contains functions to work with MSFs that include a Writer
monadic layer. This includes functions to create new MSFs that include an
additional layer, and functions to flatten that layer out of the MSF's
transformer stack.
It is based on the _strict_ writer monad Strict,
so when combining it with other modules such as mtl's,
the strict version has to be included, i.e. Strict
instead of Writer or Lazy.
Synopsis
- newtype WriterT w (m :: * -> *) a = WriterT {
- runWriterT :: m (a, w)
- type Writer w = WriterT w Identity
- runWriter :: Writer w a -> (a, w)
- execWriter :: Writer w a -> w
- mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b
- execWriterT :: Monad m => WriterT w m a -> m w
- mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- censor :: Monad m => (w -> w) -> WriterT w m a -> WriterT w m a
- listens :: Monad m => (w -> b) -> WriterT w m a -> WriterT w m (a, b)
- listen :: Monad m => WriterT w m a -> WriterT w m (a, w)
- tell :: Monad m => w -> WriterT w m ()
- writer :: Monad m => (a, w) -> WriterT w m a
- writerS :: (Monad m, Monoid s) => MSF m a (s, b) -> MSF (WriterT s m) a b
- runWriterS :: Monad m => MSF (WriterT s m) a b -> MSF m a (s, b)
- writerS' :: (Monad m, Monoid s) => MSF m a (s, b) -> MSF (WriterT s m) a b
- runWriterS' :: (Monoid s, Monad m) => MSF (WriterT s m) a b -> MSF m a (s, b)
- writerS'' :: (Monad m, Monoid w) => MSF m a (w, b) -> MSF (WriterT w m) a b
- runWriterS'' :: (Monoid s, Monad m) => MSF (WriterT s m) a b -> MSF m a (s, b)
Documentation
newtype WriterT w (m :: * -> *) a #
A writer monad parameterized by:
w- the output to accumulate.m- The inner monad.
The return function produces the output mempty, while >>=
combines the outputs of the subcomputations using mappend.
Constructors
| WriterT | |
Fields
| |
Instances
runWriter :: Writer w a -> (a, w) #
Unwrap a writer computation as a (result, output) pair.
(The inverse of writer.)
execWriter :: Writer w a -> w #
Extract the output from a writer computation.
execWriterm =snd(runWriterm)
execWriterT :: Monad m => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterTm =liftMsnd(runWriterTm)
mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b #
Map both the return value and output of a computation using the given function.
runWriterT(mapWriterTf m) = f (runWriterTm)
censor :: Monad m => (w -> w) -> WriterT w m a -> WriterT w m a #
is an action that executes the action censor f mm and
applies the function f to its output, leaving the return value
unchanged.
censorf m =pass(liftM(\ x -> (x,f)) m)runWriterT(censorf m) =liftM(\ (a, w) -> (a, f w)) (runWriterTm)
listens :: Monad m => (w -> b) -> WriterT w m a -> WriterT w m (a, b) #
is an action that executes the action listens f mm and adds
the result of applying f to the output to the value of the computation.
listensf m =liftM(id *** f) (listenm)runWriterT(listensf m) =liftM(\ (a, w) -> ((a, f w), w)) (runWriterTm)
listen :: Monad m => WriterT w m a -> WriterT w m (a, w) #
is an action that executes the action listen mm and adds its
output to the value of the computation.
runWriterT(listenm) =liftM(\ (a, w) -> ((a, w), w)) (runWriterTm)
writer :: Monad m => (a, w) -> WriterT w m a #
Construct a writer computation from a (result, output) pair.
(The inverse of runWriter.)
Writer MSF running and wrapping
writerS :: (Monad m, Monoid s) => MSF m a (s, b) -> MSF (WriterT s m) a b Source #
Build an MSF in the Writer monad from one that produces the log as an
extra output. This is the opposite of runWriterS.
Alternative implementation using lifterS
runWriterS' :: (Monoid s, Monad m) => MSF (WriterT s m) a b -> MSF m a (s, b) Source #
Alternative implementation of runWriterS using lifterS.
Alternative implementation using transS
runWriterS'' :: (Monoid s, Monad m) => MSF (WriterT s m) a b -> MSF m a (s, b) Source #
Alternative implementation of runWriterS using transS.