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 #
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Lift an M to a WriterT ω M, using the given empty as the monoid unit.
Equations
- WriterT.liftTell empty = { monadLift := fun {α : Type ?u.24} (cmd : M α) => WriterT.mk ((fun (a : α) => (a, empty)) <$> cmd) }
Instances For
Equations
- WriterT.instMonadOfEmptyCollectionOfAppend = WriterT.monad ∅ fun (x1 x2 : ω) => x1 ++ x2
Equations
- WriterT.instMonadOfMonoid = WriterT.monad 1 fun (x1 x2 : ω) => x1 * x2
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- WriterT.instMonadFunctor = { monadMap := fun {α : Type ?u.18} (k : {β : Type ?u.18} → M β → M β) (w : M (α × ω)) => WriterT.mk (k w) }
Equations
- WriterT.adapt f cmd = WriterT.mk (Prod.map id f <$> cmd)
Instances For
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]
Equations
- monadWriterAdapterTrans = { adaptWriter := fun {α : Type ?u.30} (f : ω → ω) => monadMap fun {α : Type ?u.30} => adaptWriter f }
Equations
- instMonadWriterAdapterWriterTOfMonad = { adaptWriter := fun {α : Type ?u.18} => WriterT.adapt }
reduce the equivalence between two writer monads to the equivalence between their underlying monad
Equations
- WriterT.equiv F = { toFun := fun (f : m₁ (α₁ × ω₁)) => WriterT.mk (F f), invFun := fun (f : m₂ (α₂ × ω₂)) => WriterT.mk (F.symm f), left_inv := ⋯, right_inv := ⋯ }