Skip to content

Commit 96e1141

Browse files
committed
[ week8 ] some of our favourite categories; Paths
1 parent c8c8c84 commit 96e1141

File tree

1 file changed

+85
-11
lines changed

1 file changed

+85
-11
lines changed

lectures/Week8.agda

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
{-# OPTIONS --type-in-type #-}
12
module Week8 where
23

3-
---------------------------------------------------------------------------
4-
-- Monoids
5-
---------------------------------------------------------------------------
4+
open import Relation.Binary.PropositionalEquality
5+
using (_≡_; refl; cong; sym; module ≡-Reasoning)
6+
7+
open import Function using (_∘′_; id)
8+
9+
open import Week7 hiding (Category; _++_)
10+
611

712
-- Remember categories? A category is a fancy monoid:
813
-- - It has a type of objects
9-
-- - It has a type of morphism with a source & target object
14+
-- - It has a type of morphisms with a source & target object
1015
-- - For each object, it has a unit morphism from the object to itself
1116
-- - It has a way to combine two morphisms
12-
-- (provided the target of one is the source of the other)
17+
-- (provided the target of the first is the source of the second)
1318
-- - Combining morphisms is associative
1419

15-
16-
open import Relation.Binary.PropositionalEquality
17-
using (_≡_; refl; cong; sym; module ≡-Reasoning)
18-
19-
open import Week7 hiding (Category)
20-
2120
---------------------------------------------------------------------------
2221
-- Category
2322
---------------------------------------------------------------------------
@@ -41,6 +40,81 @@ open Category
4140

4241
-- Our favourite categories
4342

43+
open import Data.Nat.Base using (ℕ; _≤_)
44+
import Data.Nat.Properties as ℕ
45+
46+
ℕ≤-cat : Category
47+
ℕ≤-cat .Object =
48+
ℕ≤-cat .Morphism = _≤_
49+
ℕ≤-cat ._then_ = ℕ.≤-trans
50+
ℕ≤-cat .identity = ℕ.≤-refl
51+
ℕ≤-cat .then-assoc = λ _ _ _ ℕ.≤-irrelevant _ _
52+
ℕ≤-cat .then-identity = λ _ ℕ.≤-irrelevant _ _
53+
ℕ≤-cat .identity-then = λ _ ℕ.≤-irrelevant _ _
54+
55+
-- Category of monoids
56+
57+
-- When are monoid homomorphisms equal?
58+
59+
postulate
60+
monHomEq : {M N : Monoid} (f g : HomoMorphism M N)
61+
HomoMorphism.function f ≡ HomoMorphism.function g
62+
f ≡ g
63+
{-
64+
monHomEq record { function = f ; mempty-resp = f-mempty ; <>-resp = f-<> }
65+
record { function = .f ; mempty-resp = g-mempty ; <>-resp = g-<> } refl
66+
= {!!}
67+
-}
68+
69+
monoid-cat : Category
70+
monoid-cat .Object = Monoid
71+
monoid-cat .Morphism M N = HomoMorphism M N
72+
(monoid-cat ._then_ f g) .HomoMorphism.function
73+
= HomoMorphism.function g ∘′ HomoMorphism.function f
74+
(monoid-cat then f) g .HomoMorphism.mempty-resp rewrite HomoMorphism.mempty-resp f | HomoMorphism.mempty-resp g = refl
75+
(monoid-cat then f) g .HomoMorphism.<>-resp x y rewrite HomoMorphism.<>-resp f x y = HomoMorphism.<>-resp g _ _
76+
monoid-cat .identity .HomoMorphism.function = id
77+
monoid-cat .identity .HomoMorphism.mempty-resp = refl
78+
monoid-cat .identity .HomoMorphism.<>-resp x y = refl
79+
monoid-cat .then-assoc f g h = monHomEq _ _ refl
80+
monoid-cat .then-identity f = monHomEq _ _ refl
81+
monoid-cat .identity-then f = monHomEq _ _ refl
82+
83+
84+
open import Data.Unit.Base using (⊤)
85+
{-
86+
87+
fancier : Monoid → Category
88+
fancier M .Object = ⊤
89+
fancier M .Morphism = λ _ _ → Monoid.Carrier M
90+
fancier M ._then_ = {!!}
91+
fancier M .identity = {!!}
92+
fancier M .then-assoc = {!!}
93+
fancier M .then-identity = {!!}
94+
fancier M .identity-then = {!!}
95+
-}
96+
4497
-- Squish but for categories!
4598

99+
data Path {O : Set} (M : O O Set) (s : O) : O Set where
100+
[] : Path M s s
101+
_∷_ : {m t} M s m Path M m t Path M s t
102+
103+
_++_ : {O M} {s m t : O} Path M s m Path M m t Path M s t
104+
[] ++ q = q
105+
(step ∷ p) ++ q = step ∷ (p ++ q)
106+
107+
module _ (C : Category) where
108+
109+
module C = Category C
110+
open C renaming (Object to O; Morphism to M)
111+
112+
squish : {s t} Path M s t M s t
113+
squish [] = C.identity
114+
squish (step ∷ path) = step C.then squish path
115+
116+
squish-++ : {s m t} (p : Path M s m) (q : Path M m t)
117+
squish (p ++ q) ≡ squish p C.then squish q
118+
squish-++ = {!!}
119+
46120
-- Proof by reflection

0 commit comments

Comments
 (0)