Predicate transformers for arbitrary postcondition shapes #
This module defines the type PredTrans ps of predicate transformers for a given ps : PostShape.
PredTrans forms the semantic domain of the weakest precondition interpretation
WP in which we interpret monadic programs.
A predicate transformer x : PredTrans ps α is a function that takes a postcondition
Q : PostCond α ps and returns a precondition x.apply Q : Assertion ps, with the additional
monotonicity property that the precondition is stronger the stronger the postcondition is:
Q₁ ⊢ₚ Q₂ → x.apply Q₁ ⊢ₛ x.apply Q₂.
Since PredTrans itself forms a monad, we can interpret monadic programs by writing
a monad morphism into PredTrans; this is exactly what WP encodes.
This module defines interpretations of common monadic operations, such as get, throw,
liftM, etc.
Any predicate transformer that is conjunctive is also monotonic.
Equations
Instances For
The type of predicate transformers for a given ps : PostShape and return type α : Type. A
predicate transformer x : PredTrans ps α is a function that takes a postcondition Q : PostCond α ps and returns a precondition x.apply Q : Assertion ps.
Apply the predicate transformer to a postcondition.
- conjunctive : Conjunctive self.apply
The predicate transformer is conjunctive:
t (Q₁ ∧ₚ Q₂) ⊣⊢ₛ t Q₁ ∧ t Q₂. So the stronger the postcondition, the stronger the resulting precondition.
Instances For
The identity predicate transformer that transforms the postcondition's assertion about the return
value into an assertion about a.
Equations
Instances For
Adds the ability to make assertions about a state of type σ to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .arg σ ps. This is done by
interpreting StateT σ (PredTrans ps) α into PredTrans (.arg σ ps) α.
This can be used to for all kinds of state-like effects, including reader effects or append-only states, by interpreting them as states.
Equations
Instances For
Adds the ability to make assertions about exceptions of type ε to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .except ε ps. This is done by
interpreting ExceptT ε (PredTrans ps) α into PredTrans (.except ε ps) α.
This can be used for all kinds of exception-like effects, such as early termination, by interpreting them as exceptions.
Equations
Instances For
Adds the ability to make assertions about early termination to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .except PUnit ps. This is done by
interpreting OptionT (PredTrans ps) α into PredTrans (.except PUnit ps) α, which models the type
Option as being equivalent to Except PUnit.