Documentation

Linglib.Semantics.Composition.Writer

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 #

Main results #

Implementation notes #

References #

instance WriterT.instLawfulMonadList {M : Type u → Type v} {P : Type u} [Monad M] [LawfulMonad M] :
LawfulMonad (WriterT (List P) M)

A writer monad with list logs is lawful over any lawful monad.

def Writer.mk {ω A : Type u} (a : A) (w : ω) :
Writer ω A

Writer.mk a w is the computation with value a and log w.

Equations
Instances For
    def Writer.val {ω A : Type u} (m : Writer ω A) :
    A

    The value of a computation is the first component of its run.

    Equations
    • m.val = (WriterT.run m).fst
    Instances For
      def Writer.log {ω A : Type u} (m : Writer ω A) :
      ω

      The log of a computation is the second component of its run.

      Equations
      • m.log = (WriterT.run m).snd
      Instances For
        theorem Writer.ext {ω A : Type u} {m₁ m₂ : Writer ω A} (hv : m₁.val = m₂.val) (hl : m₁.log = m₂.log) :
        m₁ = m₂
        theorem Writer.ext_iff {ω A : Type u} {m₁ m₂ : Writer ω A} :
        m₁ = m₂ ↔ m₁.val = m₂.val ∧ m₁.log = m₂.log
        @[simp]
        theorem Writer.val_mk {ω A : Type u} (a : A) (w : ω) :
        (Writer.mk a w).val = a
        @[simp]
        theorem Writer.log_mk {ω A : Type u} (a : A) (w : ω) :
        (Writer.mk a w).log = w
        @[simp]
        theorem Writer.val_tell {ω : Type u} (w : ω) :
        (tell w).val = PUnit.unit
        @[simp]
        theorem Writer.log_tell {ω : Type u} (w : ω) :
        (tell w).log = w
        @[simp]
        theorem Writer.val_pure {ω A : Type u} (empty : ω) (append : ω → ω → ω) (a : A) :
        (pure a).val = a
        @[simp]
        theorem Writer.log_pure {ω A : Type u} (empty : ω) (append : ω → ω → ω) (a : A) :
        (pure a).log = empty
        @[simp]
        theorem Writer.val_bind {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (m : Writer ω A) (f : A → Writer ω B) :
        (m >>= f).val = (f m.val).val

        The value of m >>= f is the value of f at the value of m, so the log of m never reaches it.

        @[simp]
        theorem Writer.log_bind {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (m : Writer ω A) (f : A → Writer ω B) :
        (m >>= f).log = append m.log (f m.val).log
        @[simp]
        theorem Writer.val_map {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (f : A → B) (m : Writer ω A) :
        (f <$> m).val = f m.val
        @[simp]
        theorem Writer.log_map {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (f : A → B) (m : Writer ω A) :
        (f <$> m).log = m.log
        @[simp]
        theorem Writer.val_seq {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (f : Writer ω (A → B)) (m : Writer ω A) :
        (f <*> m).val = f.val m.val
        @[simp]
        theorem Writer.log_seq {ω A B : Type u} (empty : ω) (append : ω → ω → ω) (f : Writer ω (A → B)) (m : Writer ω A) :
        (f <*> m).log = append f.log m.log
        theorem Writer.log_prefix_bind {A B P : Type u} (m : Writer (List P) A) (f : A → Writer (List P) B) :
        m.log <+: (m >>= f).log

        The log of m >>= f extends the log of m, so composition is isotone for the prefix order on list logs.