Built with Alectryon, running Coq+SerAPI v8.16.0+0.16.3. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
From Tealeaves Require Export
Classes.Kleisli.Monad
Classes.Categorical.Applicative.(** * The [option] Monad *)(** [option] is defined by the Coq standard library. *)(**********************************************************************)(** ** Functor Instance *)(**********************************************************************)#[export] InstanceMap_option: Map option :=
funAB (f: A -> B) (m: option A) =>
match m with
| Some a => Some (f a)
| None => None
end.
Functor option
Functor option
forallA : Type, map id = id
forall (ABC : Type) (f : A -> B) (g : B -> C),
map g ∘ map f = map (g ∘ f)
forallA : Type, map id = id
A: Type
map id = id
now ext [|].
forall (ABC : Type) (f : A -> B) (g : B -> C),
map g ∘ map f = map (g ∘ f)
A, B, C: Type f: A -> B g: B -> C
map g ∘ map f = map (g ∘ f)
now ext [|].Qed.(** ** Applicative Instance *)(**********************************************************************)#[export] InstancePure_option: Pure option :=
@Some.
Mult option
Mult option
forallAB : Type,
option A * option B -> option (A * B)
A, B: Type a: A b: B
option (A * B)
A, B: Type a: A
option (A * B)
A, B: Type b: B
option (A * B)
A, B: Type
option (A * B)
A, B: Type a: A b: B
option (A * B)
exact (Some (a, b)).
A, B: Type a: A
option (A * B)
exact None.
A, B: Type b: B
option (A * B)
exact None.
A, B: Type
option (A * B)
exact None.Defined.
Applicative option
Applicative option
forall (AB : Type) (f : A -> B) (x : A),
map f (pure x) = pure (f x)
forall (ABCD : Type) (f : A -> C) (g : B -> D)
(x : option A) (y : option B),
mult (map f x, map g y) =
map (map_tensor f g) (mult (x, y))
forall (ABC : Type) (x : option A) (y : option B)
(z : option C),
map associator (mult (mult (x, y), z)) =
mult (x, mult (y, z))
forall (A : Type) (x : option A),
map left_unitor (mult (pure tt, x)) = x
forall (A : Type) (x : option A),
map right_unitor (mult (x, pure tt)) = x
forall (AB : Type) (a : A) (b : B),
mult (pure a, pure b) = pure (a, b)
forall (AB : Type) (f : A -> B) (x : A),
map f (pure x) = pure (f x)
reflexivity.
forall (ABCD : Type) (f : A -> C) (g : B -> D)
(x : option A) (y : option B),
mult (map f x, map g y) =
map (map_tensor f g) (mult (x, y))
destruct x as [x|];
destruct y as [y|];
reflexivity.
forall (ABC : Type) (x : option A) (y : option B)
(z : option C),
map associator (mult (mult (x, y), z)) =
mult (x, mult (y, z))
destruct x as [x|];
destruct y as [y|];
destruct z as [z|];
reflexivity.
forall (A : Type) (x : option A),
map left_unitor (mult (pure tt, x)) = x
destruct x as [x|]; reflexivity.
forall (A : Type) (x : option A),
map right_unitor (mult (x, pure tt)) = x
destruct x as [x|]; reflexivity.
forall (AB : Type) (a : A) (b : B),
mult (pure a, pure b) = pure (a, b)
reflexivity.Qed.(** ** Monad Instance *)(**********************************************************************)#[export] InstanceReturn_option: Return option :=
@Some.#[export] InstanceJoin_option: Monad.Join option :=
funA (m: option (option A)) =>
match m with
| Some m' => m'
| None => None
end.
Natural (@ret option Return_option)
Natural (@ret option Return_option)
forall (AB : Type) (f : A -> B),
map f ∘ ret = ret ∘ map f
reflexivity.Qed.
Natural (@Monad.join option Join_option)
Natural (@Monad.join option Join_option)
forall (AB : Type) (f : A -> B),
map f ∘ Monad.join = Monad.join ∘ map f