Relating optional values #
Option.Rel r o₁ o₂ lifts a relation to optional values: both are none, or both are some with
related contents. Core states only its four constructor cases. This module adds that it inherits
reflexivity, symmetry and transitivity from r, is monotone in r, reduces to equality for
r = (· = ·), and is preserved by Option.bind with related continuations. Observing a
computation that may fail as an Option and relating results up to r uses exactly these facts.
Main results #
Option.rel_refl,Option.Rel.symm,Option.Rel.trans,Option.Rel.mono:Option.Relinherits the properties ofr.Option.rel_eq_iff: lifting equality gives equality.Option.Rel.bind: binding related values to related continuations gives related values.
theorem Option.Rel.bind {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {r : α → β → Prop} {s : γ → δ → Prop} {o₁ : Option α} {o₂ : Option β} (h : Rel r o₁ o₂) {f : α → Option γ} {g : β → Option δ} (hfg : ∀ (a : α) (b : β), r a b → Rel s (f a) (g b)) :
Binding related values to continuations that take related arguments to related results gives related results.