Primitive.agda 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {-# OPTIONS --type-in-type #-}
  2. module Primitive where
  3. infixr 2 _,_
  4. record Σ (A : Set)(B : A → Set) : Set where
  5. constructor _,_
  6. field fst : A
  7. snd : B fst
  8. open Σ
  9. data ⊤ : Set where
  10. tt : ⊤
  11. ∃ : {A : Set}(B : A → Set) → Set
  12. ∃ B = Σ _ B
  13. infix 10 _≡_
  14. data _≡_ {A : Set}(a : A) : {B : Set} → B → Set where
  15. refl : a ≡ a
  16. trans : ∀ {A B C}{a : A}{b : B}{c : C} → a ≡ b → b ≡ c → a ≡ c
  17. trans refl p = p
  18. sym : ∀ {A B}{a : A}{b : B} → a ≡ b → b ≡ a
  19. sym refl = refl
  20. resp : ∀ {A}{B : A → Set}{a a' : A} →
  21. (f : (a : A) → B a) → a ≡ a' → f a ≡ f a'
  22. resp f refl = refl
  23. Cat : Set
  24. Cat =
  25. ∃ λ (Obj : Set) →
  26. ∃ λ (Hom : Obj → Obj → Set) →
  27. ∃ λ (id : ∀ X → Hom X X) →
  28. ∃ λ (_○_ : ∀ {X Y Z} → Hom Y Z → Hom X Y → Hom X Z) →
  29. ∃ λ (idl : ∀ {X Y}{f : Hom X Y} → (id Y ○ f) ≡ f) →
  30. ∃ λ (idr : ∀ {X Y}{f : Hom X Y} → (f ○ id X) ≡ f) →
  31. ∃ λ (assoc : ∀ {W X Y Z}{f : Hom W X}{g : Hom X Y}{h : Hom Y Z} →
  32. ((h ○ g) ○ f) ≡ (h ○ (g ○ f))) →
  33. Obj : (C : Cat) → Set
  34. Obj C = fst C
  35. Hom : (C : Cat) → Obj C → Obj C → Set
  36. Hom C = fst (snd C)
  37. id : (C : Cat) → ∀ X → Hom C X X
  38. id C = fst (snd (snd C))
  39. comp : (C : Cat) → ∀ {X Y Z} → Hom C Y Z → Hom C X Y → Hom C X Z
  40. comp C = fst (snd (snd (snd C)))
  41. idl : (C : Cat) → ∀ {X Y}{f : Hom C X Y} → comp C (id C Y) f ≡ f
  42. idl C = fst (snd (snd (snd (snd C))))
  43. idr : (C : Cat) → ∀ {X Y}{f : Hom C X Y} → comp C f (id C X) ≡ f
  44. idr C = fst (snd (snd (snd (snd (snd C)))))
  45. assoc : (C : Cat) → ∀ {W X Y Z}{f : Hom C W X}{g : Hom C X Y}{h : Hom C Y Z} →
  46. comp C (comp C h g) f ≡ comp C h (comp C g f)
  47. assoc C = fst (snd (snd (snd (snd (snd (snd C))))))
  48. {-
  49. record Functor (C D : Cat) : Set where
  50. field Fun : Obj C → Obj D
  51. map : ∀ {X Y} → (Hom C X Y) → Hom D (Fun X) (Fun Y)
  52. mapid : ∀ {X} → map (id C X) ≡ id D (Fun X)
  53. map○ : ∀ {X Y Z}{f : Hom C X Y}{g : Hom C Y Z} →
  54. map (_○_ C g f) ≡ _○_ D (map g) (map f)
  55. open Functor
  56. idF : ∀ C → Functor C C
  57. idF C = record {Fun = \x → x; map = \x → x; mapid = refl; map○ = refl}
  58. _•_ : ∀ {C D E} → Functor D E → Functor C D → Functor C E
  59. F • G = record {Fun = \X → Fun F (Fun G X);
  60. map = \f → map F (map G f);
  61. mapid = trans (resp (\x → map F x) (mapid G)) (mapid F);
  62. map○ = trans (resp (\x → map F x) (map○ G)) (map○ F)}
  63. record Nat {C D : Cat} (F G : Functor C D) : Set where
  64. field η : (X : Obj C) → Hom D (Fun F X) (Fun G X)
  65. law : {X Y : Obj C}{f : Hom C X Y} →
  66. _○_ D (η Y) (map F f) ≡ _○_ D (map G f) (η X)
  67. open Nat
  68. _▪_ : ∀ {C D : Cat}{F G H : Functor C D} → Nat G H → Nat F G → Nat F H
  69. _▪_ {D = D} A B =
  70. record {
  71. η = \X → _○_ D (η A X) (η B X);
  72. law = \{X}{Y} →
  73. trans (assoc D)
  74. (trans (resp (\f → _○_ D (η A Y) f) (law B))
  75. (trans (sym (assoc D))
  76. (trans (resp (\g → _○_ D g (η B X)) (law A))
  77. (assoc D))))
  78. }
  79. -}