Predicate Transformers #
This module defines the type PredTrans Pred EPred α of predicate transformers for weakest
precondition reasoning over monadic programs with exception postconditions.
A predicate transformer x : PredTrans Pred EPred α takes a normal postcondition post : α → Pred,
an exception postcondition epost : EPred, and returns a precondition of type Pred.
PredTrans forms a monad, so monadic programs can be interpreted by a monad morphism into
PredTrans; this is exactly what WP encodes.
Main definitions #
PredTrans Pred EPred α— the type of monotone predicate transformersPredTrans.pushExcept— adds an exception layer to a predicate transformerpushArg— adds a state argument to a predicate transformer- Instances for
Monad,LawfulMonad,MonadStateOf,MonadExceptOf, etc.
A monotone predicate transformer from postconditions to preconditions.
Given a return type α, a lattice Pred for assertions, and an exception assertion type EPred,
PredTrans Pred EPred α wraps a function (α → Pred) → EPred → Pred.
- apply : (α → Pred) → EPred → Pred
Apply the predicate transformer to a postcondition and exception postcondition.
Instances For
Partial order on predicate transformers, inherited from the function space.
Chain-complete partial order on predicate transformers, for fixed-point reasoning.
PredTrans is a lawful monad: all monad laws hold definitionally.
Monotonicity property for a predicate transformer: if both post and epost grow,
then the resulting precondition grows.
Instances For
apply_* simp framework #
Simp lemmas for reducing (expr).apply post epost for each monadic combinator.
Exception Handling #
Definitions for pushing and lifting exception layers through predicate transformers.
Push an Except ε α result into separate normal and exception postconditions:
ok a uses post a, and error e uses epost.head e.
Instances For
Adds an exception layer to a predicate transformer.
Given a transformer over Except ε α, produces one over α with an additional
exception postcondition for ε. The normal and error postconditions are combined
via pushExcept.
Instances For
Push an Option α result into separate normal and none postconditions:
some a uses post a, and none uses epost.head.
Instances For
Adds an early-termination layer to a predicate transformer, modelling Option as
early termination. Given a transformer over Option α, produces one over α with an
additional exception postcondition for the none case.
Instances For
Unfolding pushOption through apply.
Lift a predicate transformer to one with an additional exception layer, ignoring the new exception postcondition.
State Handling #
Definitions for adding state arguments to predicate transformers.
Adds a state argument to a predicate transformer.
Given a state-dependent transformer σ → PredTrans l e (α × σ), produces a transformer
over σ → l that threads the state through postconditions.
Instances For
Lift a predicate transformer to one with an additional exception layer (high priority).
MonadStateOf instance: get returns the state, set replaces it,
modifyGet applies a function to the state.
MonadReaderOf instance: read provides the state without consuming it.
MonadExceptOf instance for the outermost exception layer:
throw invokes the head exception postcondition, tryCatch intercepts it.
MonadExceptOf instance lifted through a state layer:
delegates throw and tryCatch to the inner PredTrans l e instance.
MonadExceptOf instance lifted through an unrelated exception layer:
delegates to the inner instance, threading the extra exception postcondition.