-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functors.agda
90 lines (74 loc) · 2.82 KB
/
Functors.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
module Functors where
open import Library
open import Categories
open Cat
record Fun {a b c d}(C : Cat {a} {b})(D : Cat {c} {d}) : Set (a ⊔ b ⊔ c ⊔ d)
where
constructor functor
field OMap : Obj C → Obj D
HMap : ∀{X Y} → Hom C X Y → Hom D (OMap X) (OMap Y)
fid : ∀{X} → HMap (iden C {X}) ≅ iden D {OMap X}
fcomp : ∀{X Y Z}{f : Hom C Y Z}{g : Hom C X Y} →
HMap (_∙_ C f g) ≅ _∙_ D (HMap f) (HMap g)
open Fun
--------------------------------------------------
{- Funtor Identidad -}
IdF : ∀{a b}{C : Cat {a} {b}} → Fun C C
IdF {C} = record{ OMap = id
; HMap = id
; fid = refl
; fcomp = refl}
--------------------------------------------------
{- Composición de funtores -}
_○_ : ∀{a b c d e f}{C : Cat {a} {b}}{D : Cat {c} {d}}{E : Cat {e} {f}} →
Fun D E → Fun C D → Fun C E
_○_ {C = C}{D}{E} F G = record{
OMap = OMap F ∘ OMap G;
HMap = HMap F ∘ HMap G;
fid =
proof
HMap F (HMap G (iden C))
≅⟨ cong (HMap F) (fid G) ⟩
HMap F (iden D)
≅⟨ fid F ⟩
iden E
∎;
fcomp = λ {_}{_}{_}{f}{g} →
proof
HMap F (HMap G (_∙_ C f g))
≅⟨ cong (HMap F) (fcomp G) ⟩
HMap F (_∙_ D (HMap G f) (HMap G g))
≅⟨ fcomp F ⟩
_∙_ E (HMap F (HMap G f)) (HMap F (HMap G g))
∎}
infix 10 _○_
--------------------------------------------------
{- ¿Cuándo dos funtores son iguales ?
Cuando
1. el mapeo de objetos es igual
2. Para cualquier par de objetos X,Y, el mapeo de Hom(X,Y) es el mismo
Notar que las pruebas de las propiedades no son relevantes.
-}
Functor-Eq : ∀{a b c d}{C : Cat {a} {b}}{D : Cat {c} {d}}{F G : Fun C D}
→ OMap F ≅ OMap G
→ (λ {X Y} → HMap F {X}{Y}) ≅ (λ {X}{Y} → HMap G {X}{Y})
→ F ≅ G
Functor-Eq {F = functor fo fh _ _} {functor .fo .fh _ _} refl refl =
cong₂ (functor fo fh)
(iir _ _)
(iext λ _ → iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)
--------------------------------------------------
Fop : ∀{a b c d}{C : Cat {a}{b}}{ D : Cat {c} {d}}
→ (F : Fun C D)
→ Fun (C Op) (D Op)
Fop (functor OMap HMap fid fcomp) = functor OMap HMap fid fcomp
--------------------------------------------------
○-idl : ∀{a b c d}{A : Cat {a} {b}}{B : Cat {c} {d}}{F : Fun A B} ->
IdF ○ F ≅ F
○-idl = Functor-Eq refl refl
○-idr : ∀{a b c d}{A : Cat {a} {b}}{B : Cat {c} {d}}{F : Fun A B} ->
F ○ IdF ≅ F
○-idr = Functor-Eq refl refl
○-assoc : ∀{a b c d e f g h}{A : Cat {a} {b}}{B : Cat {c} {d}}{C : Cat {e} {f}}{D : Cat {g} {h}}{F : Fun A B}{G : Fun B C}{H : Fun C D} ->
H ○ (G ○ F) ≅ (H ○ G) ○ F
○-assoc = Functor-Eq refl refl