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

Generalizable All Variables.

Category of streams

Object and morphism definitions

Module Stream.

  Structure Obj : Type ≔ mkObj
  { T:>𝑹π‘ͺπ’π’Žπ’π’π’‚π’… 𝑬𝑸
  ; tail:> [T] β‡’ [T] }.

  Arguments mkObj{_ } _.
  Arguments T_.
  Arguments tail_.

  Notation "'Stream.make' ⦃ 'T' ≔ T ; 'tail' ≔ tail ⦄" ≔
           (@mkObj T tail) (only parsing).

  Structure Morphism (T S : Obj) : Type ≔ mkMorphism
  { Ο„:> T β‡’ S
  ; Ο„_commutes: βŸ¨Ο„βŸ© ∘ Ο„βŽβ‹…T β‰ˆ S ∘ βŸ¨Ο„βŸ© }.

  Arguments mkMorphism{_ _ _} _.
  Arguments Ο„{_ _} _.
  Arguments Ο„_commutes{_ _} _ {_ _ _ _}.

  Notation "'Stream.make' ⦃ 'Ο„' ≔ Ο„ ⦄" ≔ (@mkMorphism _ _ Ο„ _) (only parsing).

  Program Definition Hom (T S : Obj) : Setoid ≔
    Setoid.make⦃ Carrier≔ Morphism T S
    ; Equiv≔ (Ξ» g f βˆ™ g β‰ˆ f) ⦄.
equivalence
  Show proof.
    constructor.
    - repeat intro. now rewrite H.
    - repeat intro. symmetry; now rewrite H.
    - repeat intro; etransitivity; eauto. now apply H0.

End Stream.

Export Stream.

Identity and compositon definitions

Section Defs.

  Implicit Types (T S R U : Obj).

  Infix "β‡’" ≔ Hom.

  Program Definition id {T} : T β‡’ T ≔
    Stream.make ⦃ Ο„ ≔ id[T] ⦄.
Ο„-cong
  Show proof.
    now rewrite H.

  Obligation Tactic ≔ idtac.
  Program Definition compose {T S R} : [ S β‡’ R ⟢ T β‡’ S ⟢ T β‡’ R ] ≔
    Ξ» g f ↦₂ Stream.make ⦃ Ο„ ≔ g ∘ f ⦄.
Ο„-commutes
  Show proof.
    intros T S R g f.
    destruct g as [g g_commutes]. simpl in g_commutes.
    destruct f as [f f_commutes]. simpl in f_commutes. simpl.
    intros.
    rewrite H.
    etransitivity.
    eapply Setoids.cong.
    apply f_commutes.
    reflexivity.
    apply g_commutes.
    reflexivity.
Ο„-proper
  Show proof.
    repeat intro.
    simpl.
    etransitivity. eapply Setoids.cong.
    eapply Setoids.cong. apply H1.
    etransitivity. eapply Setoids.cong.
    apply H0. reflexivity.
    apply H.
    reflexivity.

  Infix "∘" ≔ compose.

  Lemma left_id : βˆ€ T S (f : T β‡’ S), id ∘ f β‰ˆ f.
  Show proof.
    intros. simpl. intros. rewrite H.
    reflexivity.

  Lemma right_id : βˆ€ T S (f : T β‡’ S), f ∘ id β‰ˆ f.
  Show proof.
    repeat intro. simpl. now rewrite H.

  Lemma compose_assoc T R S U (f : T β‡’ R) (g : R β‡’ S) (h : S β‡’ U) : h ∘ g ∘ f β‰ˆ h ∘ (g ∘ f).
  Show proof.
    repeat intro.
    simpl. now rewrite H.

  Canonical Structure π‘Ίπ’•π’“π’†π’‚π’Ž : Category ≔
    mkCategory left_id right_id compose_assoc.

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