HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

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

The Writer monad

5 declarations
valuewriter :: Monad m => (a, w) -> WriterT w m a
#

Construct a writer computation from a (result, output) pair. (The inverse of runWriter.)

valuerunWriter :: Writer w a -> (a, w)
#

Unwrap a writer computation as a (result, output) pair. (The inverse of writer.)

The WriterT monad transformer

3 declarations
newtypenewtype 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 m >>= k combines the outputs of the subcomputations using mappend (also known as <>):

image: images/bind-WriterT.svg

Constructors

Instances23MonadTrans, Monad, Functor, MonadFix, MonadFail, Applicative, …

Writer operations

5 declarations
valuepass :: Monad m => WriterT w m (a, w -> w) -> WriterT w m a
#

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.

Lifting other operations

2 declarations