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 Import
Classes.Categorical.Applicative
Classes.Categorical.Monad (Return, ret)
Classes.Kleisli.DecoratedTraversableMonad
Functors.Early.Batch
Functors.Early.Writer.Import Batch.Notations.Import Monoid.Notations.Import DecoratedTraversableMonad.Notations.Import Product.Notations.Import Applicative.Notations.#[local] Generalizable VariablesW T A B.(** * Coalgebraic Decorated Traversable Monads *)(**********************************************************************)(** ** The <<toBatch7>> Operation *)(**********************************************************************)ClassToBatch7 (W: Type) (TU: Type -> Type) :=
toBatch7: forallAB, U A -> Batch (W * A) (T B) (U B).#[global] Arguments toBatch7 {W}%type_scope {T U}%function_scope
{ToBatch7} {A B}%type_scope _.(** ** The <<cojoin_Batch7>> Operation *)(**********************************************************************)Sectioncojoin.Context
{W: Type}
{T: Type -> Type}
`{Monoid_op W}
`{ToBatch7 W T T}.Context
{A: Type} (* original leaves *)
{A': Type} (* new leaves *)
{A'': Type}. (* new type of new leaves *)Sectionauxiliary.Context {R: Type}.Definitioncojoin_Type :=
Batch (W * A) (T A') R ->
Batch (W * A) (T A'') (Batch (W * A'') (T A') R).Definitionkey_function (w: W):
Batch (W * A'') (T A') (T A' -> R) ->
T A'' ->
Batch (W * A'') (T A') R :=
funnext_batcht =>
next_batch <⋆> mapfst_Batch (incr w) (toBatch7 (B := A') t).Definitioncojoin_Batch7_leaf_case:
Batch (W * A) (T A'') (Batch (W * A'') (T A') (T A' -> R)) ->
(* ^recursive call on cojoin of continuation *)
W * A ->
(* ^leaf in context *)
Batch (W * A) (T A'') (T A'' -> Batch (W * A'') (T A') R) :=
funrec_continue '(w, a) =>
map (F := Batch (W * A) (T A'')) (key_function w) rec_continue.Endauxiliary.Fixpointcojoin_Batch7 {R: Type}
(b: Batch (W * A) (T A') R):
Batch (W * A) (T A'') (Batch (W * A'') (T A') R) :=
match b with
| Done c => Done (Done c)
| Step continuation (w, a) =>
letnew_continuation :=
cojoin_Batch7_leaf_case
(cojoin_Batch7 (R := T A' -> R) continuation) (w, a)
in Step new_continuation (w, a)
end.Endcojoin.(** ** <<cojoin_Batch7>> as <<double_batch7>> *)(**********************************************************************)Sectionsection.Context
`{Monoid W}
`{ToBatch7 W T T}.Definitiondouble_batch7 {AA': Type} {R: Type}:
W * A -> Batch (W * A) (T A') (Batch (W * A') (T R) (T R)) :=
fun '(w, a) =>
(map (F := Batch (W * A) (T A'))
(mapfst_Batch (incr w) ∘ toBatch7) ∘
batch (W * A) (T A')) (w, a).
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type
forall '(w, a),
double_batch7 (w, a) =
Done (mapfst_Batch (incr w) ∘ toBatch7) ⧆ (w, a)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type
forall '(w, a),
double_batch7 (w, a) =
Done (mapfst_Batch (incr w) ∘ toBatch7) ⧆ (w, a)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type w: W a: A
double_batch7 (w, a) =
Done (mapfst_Batch (incr w) ∘ toBatch7) ⧆ (w, a)
reflexivity.Qed.
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type r: R
Done (Done r) = pure r
reflexivity.
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
map (key_function w) (cojoin_Batch7 continuation)
⧆ (w, a) =
map (compose (map (fun '(f, a) => f a)))
(map (compose mult)
(map strength_arrow
(map
(func : Batch (W * A'') (T A') (T A' -> R)
=>
(c, mapfst_Batch (incr w) ∘ toBatch7 ∘ id))
(runBatch double_batch7 continuation))))
⧆ (w, a)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
map (key_function w) (cojoin_Batch7 continuation)
⧆ (w, a) =
(map (compose (map (fun '(f, a) => f a)))
∘ (map (compose mult)
∘ (map strength_arrow
∘ map
(func : Batch (W * A'') (T A') (T A' -> R)
=>
(c, mapfst_Batch (incr w) ∘ toBatch7 ∘ id)))))
(runBatch double_batch7 continuation) ⧆ (w, a)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
map (key_function w) (cojoin_Batch7 continuation)
⧆ (w, a) =
map
(compose (map (fun '(f, a) => f a))
∘ (compose mult
∘ (strength_arrow
∘ (func : Batch (W * A'') (T A') (T A' -> R)
=>
(c, mapfst_Batch (incr w) ∘ toBatch7 ∘ id)))))
(runBatch double_batch7 continuation) ⧆ (w, a)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type continuation: Batch (W * A) (T A') (T A' -> R) w: W a: A IHcontinuation: cojoin_Batch7 continuation =
runBatch double_batch7 continuation
map (key_function w)
(runBatch double_batch7 continuation) ⧆ (w, a) =
map
(compose (map (fun '(f, a) => f a))
∘ (compose mult
∘ (strength_arrow
∘ (func : Batch (W * A'') (T A') (T A' -> R)
=>
(c, mapfst_Batch (incr w) ∘ toBatch7 ∘ id)))))
(runBatch double_batch7 continuation) ⧆ (w, a)
reflexivity.Qed.
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T
forallAA'R : Type,
cojoin_Batch7 ∘ batch (W * A) (T R) = double_batch7
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T
forallAA'R : Type,
cojoin_Batch7 ∘ batch (W * A) (T R) = double_batch7
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type
cojoin_Batch7 ∘ batch (W * A) (T R) = double_batch7
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type
runBatch double_batch7 ∘ batch (W * A) (T R) =
double_batch7
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', R: Type
double_batch7 = double_batch7
reflexivity.Qed.
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T
forallAA'A'' : Type,
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(@cojoin_Batch7 W T op H0 A A' A'')
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T
forallAA'A'' : Type,
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(@cojoin_Batch7 W T op H0 A A' A'')
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(@cojoin_Batch7 W T op H0 A A' A'')
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type
@cojoin_Batch7 W T op H0 A A' A'' =
(funR : Type => runBatch double_batch7)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type lemma: @cojoin_Batch7 W T op H0 A A' A'' =
(funR : Type => runBatch double_batch7)
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(@cojoin_Batch7 W T op H0 A A' A'')
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type
@cojoin_Batch7 W T op H0 A A' A'' =
(funR : Type => runBatch double_batch7)
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'', R: Type
cojoin_Batch7 = runBatch double_batch7
nowrewrite cojoin_Batch7_to_runBatch.
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type lemma: @cojoin_Batch7 W T op H0 A A' A'' =
(funR : Type => runBatch double_batch7)
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(@cojoin_Batch7 W T op H0 A A' A'')
W: Type op: Monoid_op W unit0: Monoid_unit W H: Monoid W T: Type -> Type H0: ToBatch7 W T T A, A', A'': Type lemma: @cojoin_Batch7 W T op H0 A A' A'' =
(funR : Type => runBatch double_batch7)
ApplicativeMorphism (Batch (W * A) (T A'))
(Batch (W * A) (T A'') ∘ Batch (W * A'') (T A'))
(funR : Type => runBatch double_batch7)
apply ApplicativeMorphism_runBatch.Qed.Endsection.(** ** Typeclass *)(**********************************************************************)ClassDecoratedTraversableMonad (W: Type) (T: Type -> Type)
`{Monoid_op W} `{Monoid_unit W} `{Return T} `{ToBatch7 W T T} :=
{ dtm_monoid :> Monoid W;
dtm_ret: forall (AB: Type),
toBatch7 ∘ ret (T := T) (A := A) =
Step (Done (@id (T B))) ∘ ret (T := (W ×));
dtm_extract: forall (A: Type),
extract_Batch ∘ mapfst_Batch (ret ∘ extract (W := (W ×))) ∘
toBatch7 = @id (T A);
dtm_duplicate: forall (ABC: Type),
cojoin_Batch7 ∘ toBatch7 (A := A) (B := C) =
map (F := Batch (W * A) (T B)) (toBatch7) ∘ toBatch7;
}.