Monad algebras #
This file contains two layers:
- A minimal
MonadAlgebrainterface used by existingToMathlibfiles. - A Loom-style ordered monad algebra interface
MAlgOrderedwithwp/triple.
Public credit / attribution:
- Loom project: https://github.com/verse-lab/loom
- POPL 2026 paper: "Foundational Multi-Modal Program Verifiers", Vladimir Gladshtein, George Pîrlea, Qiyuan Zhao, Vitaly Kurin, and Ilya Sergey. DOI: https://doi.org/10.1145/3776719
The ordered monad algebra perspective (MAlgOrdered, wp, triple) in this file is adapted from
Loom's MonadAlgebras development.
Loom-style ordered monad algebras #
Ordered monad algebra interface used for quantitative WP/triple reasoning.
- μ : m l → l
Instances
Weakest precondition induced by μ.
Instances For
Hoare-style triple induced by wp.
Instances For
wp is functorial in the program return value.
wp preserves applicative sequencing.
Rule for pure computations in Triple.
Rule for map in Triple.
Monotonicity of Triple in its postcondition.
Monotonicity of Triple in its precondition.
Transformer lifting instances #
Lift an ordered monad algebra through StateT.
Lift an ordered monad algebra through ReaderT.
Lift an ordered monad algebra through ExceptT by interpreting exceptions as ⊥.
Lift an ordered monad algebra through OptionT by interpreting none as ⊥.
Honest exception WP #
wpExc is a derived weakest-precondition combinator for ExceptT that records both
a success postcondition postOk : α → l and a failure postcondition postErr : ε → l,
rather than collapsing failures to ⊥. Symmetrically, wpOpt is the analogue for
OptionT.
These are derived: they use only the unary algebra MAlgOrdered m l of the underlying
monad. The standard MAlgOrdered (ExceptT ε m) / MAlgOrdered (OptionT m) lifts then
correspond to wpExc · · (fun _ => ⊥) and wpOpt · · ⊥ respectively, which is the
"lossy" case. The honest combinators come with their own pure/throw/bind/
tryCatch rules that enable side-by-side reasoning about success and failure paths.
Honest weakest precondition for ExceptT: takes a success postcondition postOk
and a failure postcondition postErr, and returns the unary wp over the underlying
monad with the postcondition split by case.
Instances For
Honest weakest precondition for OptionT: takes a some postcondition and a
none postcondition.
Instances For
throw e is ExceptT.mk (pure (Except.error e)).
Bind law for wpExc: only the success branch threads through the post-bind
continuation; the failure postcondition is preserved at every step.
Catch law for wpExc: tryCatch x h exchanges its failure postcondition for the
honest WP of the handler.
wpExc is monotone in both postconditions.