Writer Monad for Compositional Side-Effects #
@cite{giorgolo-asudeh-2012} @cite{shan-2001}
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
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 @cite{potts-2005}'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 PostSuppositional.lean for the same pattern applied to dynamic GQs.
The Writer monad: a value paired with an accumulated log.
In @cite{giorgolo-asudeh-2012}'s notation, Writer P A is M(A),
where the second component is a collection of logged items of type P,
represented as a List for computability.
- val : A
The at-issue value
- log : List P
Accumulated side-effect log
Instances For
η (unit): lift a pure value with an empty log.
Ordinary lexical items are η-lifted:
⟦john⟧ = η(j), ⟦likes⟧ = η(λyλx.like(x,y))
Instances For
⋆ (bind): sequence computations, combining logs.
⟨x, P⟩ ⋆ f = ⟨π₁(f x), P ++ π₂(f x)⟩
The function f receives only the value x, not the log P.
This enforces @cite{potts-2005}'s restriction: side-issue content
(in the log) is invisible to subsequent at-issue computation.
Instances For
tell (write): log a single item.
Used by CI-contributing expressions to add propositions to the
side-issue dimension. In @cite{giorgolo-asudeh-2012}:
write(t) = ⟨⊥, {t}⟩
Instances For
Monadic application (⊸-elimination in Glue).
A(f)(x) = f ⋆ λg. x ⋆ λy. η(g y)
Both function and argument may carry side-effects; all side-effects are combined in the result.
Equations
- mf.app mx = mf.bind fun (f : A → B) => mx.bind fun (x : A) => Semantics.Composition.WriterMonad.Writer.pure (f x)