Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype WriterT w (m :: Type -> Type) a = WriterT {
- runWriterT :: m (a, w)
- type Writer w = WriterT w Identity
- tell :: forall (m :: Type -> Type) w. Monad m => w -> WriterT w m ()
- listen :: forall (m :: Type -> Type) w a. Monad m => WriterT w m a -> WriterT w m (a, w)
- listens :: forall (m :: Type -> Type) w b a. Monad m => (w -> b) -> WriterT w m a -> WriterT w m (a, b)
- censor :: forall (m :: Type -> Type) w a. Monad m => (w -> w) -> WriterT w m a -> WriterT w m a
- 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
- writer :: forall (m :: Type -> Type) a w. Monad m => (a, w) -> WriterT w m a
- writerS :: (Functor m, Monad m, Monoid w) => Automaton m a (w, b) -> Automaton (WriterT w m) a b
- runWriterS :: (Functor m, Monad m) => Automaton (WriterT w m) a b -> Automaton m a (w, b)
Documentation
newtype WriterT w (m :: Type -> Type) 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
.
WriterT | |
|
Instances
tell :: forall (m :: Type -> Type) w. Monad m => w -> WriterT w m () #
is an action that produces the output tell
ww
.
listen :: forall (m :: Type -> Type) w a. 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
(listen
m) =liftM
(\ (a, w) -> ((a, w), w)) (runWriterT
m)
listens :: forall (m :: Type -> Type) w b a. 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.
listens
f m =liftM
(id *** f) (listen
m)runWriterT
(listens
f m) =liftM
(\ (a, w) -> ((a, f w), w)) (runWriterT
m)
censor :: forall (m :: Type -> Type) w a. 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.
censor
f m =pass
(liftM
(\ x -> (x,f)) m)runWriterT
(censor
f m) =liftM
(\ (a, w) -> (a, f w)) (runWriterT
m)
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.
execWriter
m =snd
(runWriter
m)
execWriterT :: Monad m => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterT
m =liftM
snd
(runWriterT
m)
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
(mapWriterT
f m) = f (runWriterT
m)
writer :: forall (m :: Type -> Type) a w. Monad m => (a, w) -> WriterT w m a #
Construct a writer computation from a (result, output) pair.
(The inverse of runWriter
.)