Writer Monad for Compositional Side-Effects #
The Writer monad ⟨M, η, ⋆⟩ models meaning dimensions that accumulate
side-effect information during compositional interpretation:
- M (the functor): maps a type
Ato paired valuesA × List P - η (unit/pure): lifts a value with an empty log
- ⋆ (bind): sequences computations, combining their logs
The carrier is mathlib's Writer (List P) A (= WriterT (List P) Id A),
whose Monad instance comes from mathlib's [EmptyCollection ω] [Append ω]
instance for WriterT. This file adds the domain-named surface
(Writer.mk/val/log/tell), projection simp lemmas, and the
LawfulMonad instance for list logs.
This pattern unifies several linglib constructions:
| Phenomenon | Value | Log |
|---|---|---|
| Conventional implicatures | at-issue content | CI propositions |
| Post-suppositions | DRS content | cardinality tests |
| Expressives | denotation | speaker attitude |
The Writer monad enforces [Pot05]'s flow restriction structurally:
bind's function argument receives only the value, never the log. At-issue
content can flow into side-issue computations, but side-issue content cannot
leak back into at-issue computation.
See Studies/Charlow2021.lean (PostSupp) for the same pattern applied to
dynamic GQs, with the log monoid (Update S, dseq, test ⊤) in place of
List P.
The accumulated side-effect log of a Writer computation.
Equations
- m.log = (WriterT.run m).snd
Instances For
tell (write): log a single item. Used by CI-contributing expressions
to add propositions to the side-issue dimension; in [GA12]:
write(t) = ⟨⊥, {t}⟩. (PUnit rather than Unit keeps it
universe-polymorphic; at Type 0 they coincide.)
Equations
- Writer.tell p = Writer.mk PUnit.unit [p]
Instances For
Projection lemmas for list logs #
Monad laws #
The Monad (Writer (List P)) instance is mathlib's
[EmptyCollection ω] [Append ω] instance for WriterT; the laws hold
because (List P, ++, []) is a monoid.
Log monotonicity #
The log only grows: bind's output log extends the input log.
Side-effects are permanent: once logged, an item stays in the log.