Moduletransformers-0.6.1.1Haskell2010
Control.Monad.Trans.Writer.CPS
The strict WriterT monad transformer, which adds collection of outputs (such as a count or string output) to a given monad.
This monad transformer provides only limited access to the output during the computation. For more general access, use Control.Monad.Trans.State instead.
This version builds its output strictly and uses continuation-passing-style to achieve constant space usage. This transformer can be used as a drop-in replacement for Control.Monad.Trans.Writer.Strict.
- 2 types
- 15 values
- Packagetransformers-0.6.1.1
- Exports17
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceCPS.hs
The Writer monad
5 declarationsConstruct a writer computation from a (result, output) pair. (The inverse of runWriter.)
Unwrap a writer computation as a (result, output) pair. (The inverse of writer.)
Extract the output from a writer computation.
execWriter m = snd (runWriter m)
The WriterT monad transformer
5 declarationsInstances11MonadTrans, Monad, Functor, MonadFix, MonadFail, Applicative, …
MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonad m => Monad (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSFunctor m => Functor (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonadFix m => MonadFix (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonadFail m => MonadFail (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Functor m, Monad m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Functor m, MonadPlus m) => Alternative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Functor m, MonadPlus m) => MonadPlus (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonadIO m => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSGeneric (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPStype Rep (WriterT w m a) = D1 ('MetaDataDefined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS"WriterT"
"Control.Monad.Trans.Writer.CPS"
"transformers-0.6.1.1-a11a"
'True) (C1 ('MetaCons"WriterT"
'PrefixI 'True) (S1 ('MetaSel ('Just"unWriterT"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (w -> m (a, w)))))
Construct a writer computation from a (result, output) computation. (The inverse of runWriterT.)
Unwrap a writer computation. (The inverse of writerT.)
Extract the output from a writer computation.
execWriterT m = liftM snd (runWriterT m)
Map both the return value and output of a computation using the given function.
runWriterT (mapWriterT f m) = f (runWriterT m)
Writer operations
5 declarationstell w is an action that produces the output w.
listen m is an action that executes the action m and adds its
output to the value of the computation.
runWriterT (listen m) = liftM (\ (a, w) -> ((a, w), w)) (runWriterT m)
listens f m is an action that executes the action m 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)
pass m is an action that executes the action m, which returns
a value and a function, and returns the value, applying the function
to the output.
runWriterT (pass m) = liftM (\ ((a, f), w) -> (a, f w)) (runWriterT m)
censor f m is an action that executes the action m 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)
Lifting other operations
2 declarationsUniform lifting of a callCC operation to the new monad.
This version rolls back to the original state on entering the
continuation.
Lift a catchE operation to the new monad.