Benedikt Ahrens and RΓ©gis Spadotti— Terminal semantics for codata types in intensional Martin-Löf type theory
Table of contents
Index
Require Import Theory.Category.
Require Import Theory.Functor.
Require Import Theory.RelativeComonad.

Generalizable All Variables.

Comodule over relative comonad definition

Structure Comodule `{F : Functor π’ž π’Ÿ} (T : RelativeComonad F) (β„° : Category) : Type ≔ mkComodule
{ M:>π’ž β†’ β„°
; mcobind:βˆ€ {C D}, [ T C β‡’ F D ⟢ M C β‡’ M D ]
; mcobind_counit:βˆ€ {C}, mcobind counit[ C ] β‰ˆ id[ M C ]
; mcobind_mcobind:βˆ€ {C D E} {f : T C β‡’ F D} {g : T D β‡’ F E},
                         mcobind(g) ∘ mcobind(f) β‰ˆ mcobind(g ∘ Tβ‹…cobind(f)) }.

Arguments mkComodule{_ _ _ _ _ _ _} _ _.
Arguments M{_ _ _ _ _} _ _.
Arguments mcobind{_ _ _ _ _} _ {_ _}.
Arguments mcobind_counit{_ _ _ _ _} _ {_}.
Arguments mcobind_mcobind{_ _ _ _ _} _ {_ _ _ _ _}.

Notation "M 'β‹…mcobind'" ≔ (mcobind M) (at level 0).

Notation "'Comodule.make' ⦃ 'M' ≔ M ; 'mcobind' ≔ mcobind ⦄" ≔
  (@mkComodule _ _ _ _ _ M mcobind _ _) (only parsing).

Functoriality of comodule

  Context `{F : Functor π’ž π’Ÿ} {T : RelativeComonad F} {β„°} (M : Comodule T β„°).

  Program Definition mlift {A B} : [ A β‡’ B ⟢ M A β‡’ M B ] ≔
    Ξ» f ↦ Mβ‹…mcobind (Fβ‹…f ∘ counit[ A ]).
  Show proof.
    intros x y eq_xy. now rewrite eq_xy.

  Lemma mlift_id A : id[ M A ] β‰ˆ mlift id[ A ].
  Show proof.
    simpl. rewrite <- identity, left_id, mcobind_counit.
    reflexivity.

  Lemma mlift_compose A B C (f : A β‡’ B) (g : B β‡’ C) : mlift (g ∘ f) β‰ˆ (mlift g) ∘ (mlift f).
  Show proof.
    simpl.
    rewrite mcobind_mcobind,
            compose_assoc,
            counit_cobind,
            <- compose_assoc,
            <- map_compose.
    reflexivity.

  Definition MLift : Functor π’ž β„° ≔ mkFunctor mlift_id mlift_compose.

Morphism of comodules

Structure Morphism `{F : Functor π’ž π’Ÿ} {T : RelativeComonad F} {β„°} (M N : Comodule T β„°) : Type ≔ mkMorphism
{ Ξ±:> βˆ€ C, M C β‡’ N C
; Ξ±_commutes: βˆ€ {C D} {f : T C β‡’ F D}, Ξ±(D) ∘ Mβ‹…mcobind f β‰ˆ Nβ‹…mcobind f ∘ Ξ±(C) }.

Arguments mkMorphism{_ _ _ _ _ _ _ _} _.
Arguments Ξ±{_ _ _ _ _ _ _} _ _.
Arguments Ξ±_commutes{_ _ _ _ _ _ _} _ {_ _ _}.

Notation "'Comodule.make' ⦃ 'Ξ±' ≔ Ξ± ⦄" ≔
         (@mkMorphism _ _ _ _ _ _ _ Ξ± _) (only parsing).

Module Morphism.

  Section id_composition.

    Context `{F : Functor π’ž π’Ÿ} {T : RelativeComonad F} {β„° : Category}.

    Program Definition Hom (M N : Comodule T β„°) : Setoid ≔
      Setoid.make ⦃ Carrier ≔ Morphism M N
                  ; Equiv≔ Ξ» f g βˆ™ βˆ€ x, f x β‰ˆ g x ⦄.
    Show proof.
      constructor.
      - intros f x; reflexivity.
      - intros f g eq_fg x. symmetry. apply eq_fg.
      - intros f g h eq_fg eq_gh; etransitivity; eauto.

    Local Infix "β‡’" ≔ Hom.

    Program Definition id {M : Comodule T β„°} : M β‡’ M ≔
      Comodule.make ⦃ Ξ± ≔ Ξ» C βˆ™ id[ M C ] ⦄.
    Show proof.
      now rewrite left_id, right_id.

    Program Definition compose {M N P : Comodule T β„°} : [ N β‡’ P ⟢ M β‡’ N ⟢ M β‡’ P ] ≔
      Ξ» g f ↦₂ Comodule.make ⦃ Ξ± ≔ Ξ» C βˆ™ g(C) ∘ f(C) ⦄.
    Show proof.
      rewrite <- compose_assoc; rewrite <- Ξ±_commutes.
      rewrite compose_assoc; rewrite Ξ±_commutes; rewrite compose_assoc.
      reflexivity.
    Show proof.
      intros f₁ fβ‚‚ eq_f₁fβ‚‚ g₁ gβ‚‚ eq_g₁gβ‚‚ x. simpl.
      apply Ξ β‚‚.cong; [ apply eq_f₁fβ‚‚ | apply eq_g₁gβ‚‚ ].

  End id_composition.

End Morphism.
Benedikt Ahrens and RΓ©gis Spadotti— Terminal semantics for codata types in intensional Martin-Löf type theory
Table of contents
Index