Writer monads #
This file introduces monads for managing immutable, appendable state. Common applications are logging monads where the monad logs messages as the computation progresses.
References #
- tell (w : ω) : M PUnit.{u + 1}
Emit an output
w
. Capture the output produced by
f
, without intercepting.Buffer the output produced by
f
asw
, then emit(← f).2 w
in its place.
Instances
Equations
Equations
Creates an instance of Monad
, with explicitly given empty
and append
operations.
Previously, this would have used an instance of [Monoid ω]
as input.
In practice, however, WriterT
is used for logging and creating lists so restricting to
monoids with Mul
and One
can make WriterT
cumbersome to use.
This is used to derive instances for both [EmptyCollection ω] [Append ω]
and [Monoid ω]
.
Equations
Instances For
Equations
Equations
Equations
Equations
Equations
Equations
Adapt a monad stack, changing the type of its top-most environment.
This class is comparable to Control.Lens.Magnify,
but does not use lenses (why would it), and is derived automatically for any transformer
implementing MonadFunctor
.
- adaptWriter {α : Type u} : (ω → ω) → m α → m α
Instances
Transitivity.
see Note [lower instance priority]