Writer monads for side-issue meaning #
A computation of the writer monad Writer ω yields a value and logs output in ω. Giorgolo and
Asudeh model conventional implicature this way, in Shan's monadic program: the value of an
expression is its at-issue content, the log collects the side-issue propositions of its parts,
pure logs nothing and bind appends the logs. Forgetting the log is a monad morphism to Id,
and bind only extends the log, so content flows from the at-issue dimension into the side-issue
one and never back.
Main definitions #
Writer.val,Writer.log: the value and the log of a computation.WriterT.instLawfulMonadList: the monad laws for list logs, over any lawful monad.
Main results #
Writer.val_pure,Writer.val_bind: forgetting the log is a monad morphism.Writer.log_prefix_bind: the log ofmis a prefix of the log ofm >>= f.
Implementation notes #
- Mathlib's two
Monadinstances onWriter ω, for[Monoid ω]and for[EmptyCollection ω] [Append ω], are bothWriterT.monad empty append; the projection lemmas are stated for that monad, as mathlib statesWriterT.run_bind, and apply under either. - Mathlib proves the monad laws for monoid logs only, and lists are not a monoid there.
- Giorgolo and Asudeh take the log to be a monoid of propositions and fix it to sets under union.
They require the arrows to be isotone in the log for the preorder
x ≤ y ↔ ∃ z, x * z = y, which isx ∣ yin mathlib. The consumers here log lists, the free monoid, on which this preorder is the prefix order.
References #
A writer monad with list logs is lawful over any lawful monad.
The value of a computation is the first component of its run.
Equations
- m.val = (WriterT.run m).fst
Instances For
The log of a computation is the second component of its run.
Equations
- m.log = (WriterT.run m).snd
Instances For
The log of m >>= f extends the log of m, so composition is isotone for the prefix order
on list logs.