Monad morphisms and weakest precondition interpretations #
A WP m ps
is a WPMonad m ps
if the interpretation WP.wp
is also a monad morphism, that is,
it preserves pure
and bind
.
class
Std.Do.WPMonad
(m : Type → Type u)
(ps : outParam PostShape)
[Monad m]
extends LawfulMonad m, Std.Do.WP m ps :
Type (max 1 u)
A WP
that is also a monad morphism, preserving pure
and bind
. (They all are.)
- seq_assoc {α β γ : Type} (x : m α) (g : m (α → β)) (h : m (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
Instances
Equations
- Std.Do.Id.instWPMonad = { toLawfulMonad := Id.instLawfulMonad, toWP := Std.Do.Id.instWP, wp_pure := @Std.Do.Id.instWPMonad._proof_2, wp_bind := @Std.Do.Id.instWPMonad._proof_4 }
instance
Std.Do.StateT.instWPMonad
{m : Type → Type u}
{ps : PostShape}
{σ : Type}
[Monad m]
[WPMonad m ps]
:
WPMonad (StateT σ m) (PostShape.arg σ ps)
Equations
- Std.Do.StateT.instWPMonad = { toLawfulMonad := ⋯, toWP := Std.Do.StateT.instWP, wp_pure := ⋯, wp_bind := ⋯ }
instance
Std.Do.ReaderT.instWPMonad
{m : Type → Type u}
{ps : PostShape}
{ρ : Type}
[Monad m]
[WPMonad m ps]
:
WPMonad (ReaderT ρ m) (PostShape.arg ρ ps)
Equations
- Std.Do.ReaderT.instWPMonad = { toLawfulMonad := ⋯, toWP := Std.Do.ReaderT.instWP, wp_pure := ⋯, wp_bind := ⋯ }
instance
Std.Do.ExceptT.instWPMonad
{m : Type → Type u}
{ps : PostShape}
{ε : Type}
[Monad m]
[WPMonad m ps]
:
WPMonad (ExceptT ε m) (PostShape.except ε ps)
Equations
- Std.Do.ExceptT.instWPMonad = { toLawfulMonad := ⋯, toWP := Std.Do.ExceptT.instWP, wp_pure := ⋯, wp_bind := ⋯ }
instance
Std.Do.EStateM.instWPMonad
{ε σ : Type}
:
WPMonad (EStateM ε σ) (PostShape.except ε (PostShape.arg σ PostShape.pure))
Equations
- Std.Do.EStateM.instWPMonad = { toLawfulMonad := ⋯, toWP := Std.Do.EStateM.instWP, wp_pure := ⋯, wp_bind := ⋯ }
instance
Std.Do.Except.instWPMonad
{ε : Type}
:
WPMonad (Except ε) (PostShape.except ε PostShape.pure)
Equations
- Std.Do.Except.instWPMonad = { toLawfulMonad := ⋯, toWP := Std.Do.Except.instWP, wp_pure := ⋯, wp_bind := ⋯ }