Moduletransformers-0.6.1.1Haskell2010
Control.Monad.Trans.Writer.Lazy
The lazy 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 lazily; for a constant-space version with almost the same interface, see Control.Monad.Trans.Writer.CPS.
- 2 types
- 13 values
- Packagetransformers-0.6.1.1
- Exports15
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceLazy.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
3 declarationsA writer monad parameterized by:
w- the output to accumulate.m- The inner monad.
The return function produces the output mempty, while m >>= k
combines the outputs of the subcomputations using mappend (also
known as <>):
Constructors
WriterTrunWriterT :: m (a, w)
Instances23MonadTrans, Monad, Functor, MonadFix, MonadFail, Applicative, …
Monoid w => MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Monad m) => Monad (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyFunctor m => Functor (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadFix m) => MonadFix (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadFail m) => MonadFail (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Applicative m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyFoldable f => Foldable (WriterT w f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyTraversable f => Traversable (WriterT w f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Alternative m) => Alternative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadPlus m) => MonadPlus (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadIO m) => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadZip m) => MonadZip (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Eq w, Eq1 m) => Eq1 (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Ord w, Ord1 m) => Ord1 (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Read w, Read1 m) => Read1 (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Show w, Show1 m) => Show1 (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyContravariant m => Contravariant (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Eq w, Eq1 m, Eq a) => Eq (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Ord w, Ord1 m, Ord a) => Ord (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Read w, Read1 m, Read a) => Read (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Show w, Show1 m, Show a) => Show (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyGeneric (WriterT w m a)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazytype Rep (WriterT w m a) = D1 ('MetaDataDefined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy"WriterT"
"Control.Monad.Trans.Writer.Lazy"
"transformers-0.6.1.1-a11a"
'True) (C1 ('MetaCons"WriterT"
'PrefixI 'True) (S1 ('MetaSel ('Just"runWriterT"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (a, w)))))
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 declarationsLift a callCC operation to the new monad.
Lift a catchE operation to the new monad.