WriterT on core's weakest-precondition stack #
Core lifts a WPMonad interpretation through its own transformers (StateT, ReaderT,
ExceptT, OptionT); WriterT is Mathlib's, so its lift lives here. The carrier is ω → Pred,
indexed by the log written so far: bind multiplies the prefix's log into the continuation's,
so a postcondition that mentions the log has to be told what has already been written, and
reading the interpretation at the unit recovers the log-oblivious one.
WriterT.wpMonadOf takes explicit empty/append operations and their laws, so it also
interprets append-based logs without a Monoid instance. The monoid specialization is scoped
under WriterT.MonoidWP, and the specialization to logs combined by ++ from ∅ under core's
Std.Associative and Std.LawfulIdentity is scoped under WriterT.AppendWP, which also supplies
the writer's LawfulMonad instance (WriterT.lawfulMonad_monad). Clients opt in with
open scoped WriterT.MonoidWP or open scoped WriterT.AppendWP, or install an explicit
interpretation locally. Importing the module does not choose a writer interpretation. Exactness
over an exact base is a global instance keyed on WriterT.wpMonadOf
(WriterT.instExactWPMonadWpMonadOf), so it holds under either scope and for a local
interpretation. The @[spec] rules for tell, monadLift, mk, and run are registered in the
same two scopes, beside the entailments they wrap, so vcgen uses them exactly where a writer
interpretation is selected.
WriterT's WP interpretation: the base interpretation of the run, with the postcondition
told the log accumulated so far.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lawful writer monads #
The writer monad of explicit log operations is lawful when empty is a two-sided unit of an
associative append.
List's identity for ++ at the spelling ∅ of the writer monad's empty log. Core states it
at [], and instance search does not re-abstract the identity, an outParam, in the hypotheses
of the instances below, so they need the ∅ form.
The writer monad of an append-based log is lawful.
Interpret a writer with explicit log operations. The lawfulness witness must use the
same WriterT.monad empty append; no monoid instance is installed on the log type.
Equations
- WriterT.wpMonadOf empty append right_id assoc = { toLawfulMonad := ⋯, toWP := fun (x : Type ?u.4) => WriterT.wpInstOf append, pure_le_wp_pure := ⋯, bind_le_wp_bind := ⋯ }
Instances For
Over an exact base interpretation, the explicit writer interpretation is exact.
Alias of WriterT.instExactWPMonadWpMonadOf.
Over an exact base interpretation, the explicit writer interpretation is exact.
The explicit writer interpretation exposes its accumulated-log equation. Not @[simp]: the
scoped readings state their own equations on core's wp (WriterT.wp_apply_eq,
WriterT.AppendWP.wp_apply_eq).
Writing a log fragment extends the accumulated log with the chosen append operation.
Lifting with the chosen empty log leaves the accumulated prefix unchanged.
Starting the accumulated-log interpretation at a left identity gives the base run.
Append-based logs #
WriterT.AppendWP interprets a log combined by ++ from ∅, such as a list, under core's
Std.Associative (· ++ ·) and Std.LawfulIdentity (· ++ ·) ∅.
Opt-in writer interpretation for append-based logs: the postcondition is told the log
accumulated so far, extended on the right by ++.
Equations
- WriterT.AppendWP.instWPMonad = WriterT.wpMonadOf ∅ (fun (x1 x2 : ω) => x1 ++ x2) ⋯ ⋯
Instances For
Writing to an append-based log extends the accumulated log on the right.
A lifted base computation leaves an append-based log unchanged.
Running an append-based writer computation from the empty log.
Opt-in writer interpretation for multiplicative monoid logs.
Equations
- WriterT.MonoidWP.instWPMonad = WriterT.wpMonadOf 1 (fun (x1 x2 : ω) => x1 * x2) ⋯ ⋯
Instances For
Writing to the log advances the accumulated log the postcondition sees.
A lifted base computation writes nothing.
Running a writer computation from the empty log.
vcgen rules #
The rules for tell, monadLift, WriterT.mk and WriterT.run wrap the entailments above. The
rules for multiplicative logs are stated for the interpretation of WriterT.MonoidWP, and the
rules for append-based logs for that of WriterT.AppendWP. Each set is registered in the scope of
its interpretation, so vcgen uses it exactly where that interpretation is installed.
tell on a multiplicative log, read by WriterT.MonoidWP, multiplies the log on the right.
A lifted base computation leaves a multiplicative log unchanged.
WriterT.mk x on a multiplicative log multiplies in the log x returns.
Running a writer computation on a multiplicative log starts from the unit.
tell on an append-based log, read by WriterT.AppendWP, extends the log on the right.
A lifted base computation leaves an append-based log unchanged.
WriterT.mk x on an append-based log appends the log x returns.
Running an append-based writer computation starts from the empty log.