0
|
1 module nat where
|
|
2
|
|
3 -- Monad
|
|
4 -- Category A
|
|
5 -- A = Category
|
|
6 -- Functor T : A -> A
|
|
7 --T(a) = t(a)
|
|
8 --T(f) = tf(f)
|
|
9
|
2
|
10 open import Category -- https://github.com/konn/category-agda
|
0
|
11 open import Level
|
|
12 open Functor
|
|
13
|
1
|
14 --T(g f) = T(g) T(f)
|
|
15
|
0
|
16 Lemma1 : {c₁ c₂ l : Level} {A : Category c₁ c₂ l} (T : Functor A A) -> {a b c : Obj A} {g : Hom A b c} { f : Hom A a b }
|
|
17 -> A [ ( FMap T (A [ g o f ] )) ≈ (A [ FMap T g o FMap T f ]) ]
|
|
18 Lemma1 = \t -> IsFunctor.distr ( isFunctor t )
|
|
19
|
|
20 -- F(f)
|
|
21 -- F(a) ----> F(b)
|
|
22 -- | |
|
|
23 -- |t(a) |t(b) G(f)t(a) = t(b)F(f)
|
|
24 -- | |
|
|
25 -- v v
|
|
26 -- G(a) ----> G(b)
|
|
27 -- G(f)
|
|
28
|
5
|
29 record IsNNAT {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (D : Category c₁ c₂ ℓ) (C : Category c₁′ c₂′ ℓ′)
|
0
|
30 ( F G : Functor D C )
|
5
|
31 (NAT : (A : Obj D) → Hom C (FObj F A) (FObj G A))
|
0
|
32 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
33 field
|
|
34 naturality : {a b : Obj D} {f : Hom D a b}
|
5
|
35 → C [ C [ ( FMap G f ) o ( NAT a ) ] ≈ C [ (NAT b ) o (FMap F f) ] ]
|
0
|
36 -- uniqness : {d : Obj D}
|
5
|
37 -- → C [ NAT d ≈ NAT d ]
|
0
|
38
|
|
39
|
5
|
40 record NNAT {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (domain : Category c₁ c₂ ℓ) (codomain : Category c₁′ c₂′ ℓ′) (F G : Functor domain codomain )
|
0
|
41 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
42 field
|
5
|
43 NAT : (A : Obj domain) → Hom codomain (FObj F A) (FObj G A)
|
|
44 isNNAT : IsNNAT domain codomain F G NAT
|
0
|
45
|
5
|
46 open NNAT
|
1
|
47 Lemma2 : {c₁ c₂ l : Level} {A : Category c₁ c₂ l} {F G : Functor A A}
|
5
|
48 -> (μ : NNAT A A F G) -> {a b : Obj A} { f : Hom A a b }
|
|
49 -> A [ A [ FMap G f o NAT μ a ] ≈ A [ NAT μ b o FMap F f ] ]
|
|
50 Lemma2 = \n -> IsNNAT.naturality ( isNNAT n )
|
0
|
51
|
|
52 open import Category.Cat
|
|
53
|
|
54 -- η : 1_A -> T
|
|
55 -- μ : TT -> T
|
|
56 -- μ(a)η(T(a)) = a
|
|
57 -- μ(a)T(η(a)) = a
|
|
58 -- μ(a)(μ(T(a))) = μ(a)T(μ(a))
|
|
59
|
1
|
60 record IsMonad {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ)
|
|
61 ( T : Functor A A )
|
5
|
62 ( η : NNAT A A identityFunctor T )
|
|
63 ( μ : NNAT A A (T ○ T) T)
|
1
|
64 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
65 field
|
5
|
66 assoc : {a : Obj A} -> A [ A [ NAT μ a o NAT μ ( FObj T a ) ] ≈ A [ NAT μ a o FMap T (NAT μ a) ] ]
|
|
67 unity1 : {a : Obj A} -> A [ A [ NAT μ a o NAT η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
|
68 unity2 : {a : Obj A} -> A [ A [ NAT μ a o (FMap T (NAT η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
0
|
69
|
5
|
70 record Monad {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) (T : Functor A A) (η : NNAT A A identityFunctor T) (μ : NNAT A A (T ○ T) T)
|
1
|
71 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
6
|
72 eta : NNAT A A identityFunctor T
|
|
73 eta = η
|
|
74 mu : NNAT A A (T ○ T) T
|
|
75 mu = μ
|
1
|
76 field
|
|
77 isMonad : IsMonad A T η μ
|
0
|
78
|
2
|
79 open Monad
|
|
80 Lemma3 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
81 { T : Functor A A }
|
5
|
82 { η : NNAT A A identityFunctor T }
|
|
83 { μ : NNAT A A (T ○ T) T }
|
2
|
84 { a : Obj A } ->
|
|
85 ( M : Monad A T η μ )
|
5
|
86 -> A [ A [ NAT μ a o NAT μ ( FObj T a ) ] ≈ A [ NAT μ a o FMap T (NAT μ a) ] ]
|
2
|
87 Lemma3 = \m -> IsMonad.assoc ( isMonad m )
|
|
88
|
|
89
|
|
90 Lemma4 : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A } { f : Hom A a b}
|
|
91 -> A [ A [ Id {_} {_} {_} {A} b o f ] ≈ f ]
|
|
92 Lemma4 = \a -> IsCategory.identityL ( Category.isCategory a )
|
0
|
93
|
3
|
94 Lemma5 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
95 { T : Functor A A }
|
5
|
96 { η : NNAT A A identityFunctor T }
|
|
97 { μ : NNAT A A (T ○ T) T }
|
3
|
98 { a : Obj A } ->
|
|
99 ( M : Monad A T η μ )
|
5
|
100 -> A [ A [ NAT μ a o NAT η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
3
|
101 Lemma5 = \m -> IsMonad.unity1 ( isMonad m )
|
|
102
|
|
103 Lemma6 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
104 { T : Functor A A }
|
5
|
105 { η : NNAT A A identityFunctor T }
|
|
106 { μ : NNAT A A (T ○ T) T }
|
3
|
107 { a : Obj A } ->
|
|
108 ( M : Monad A T η μ )
|
5
|
109 -> A [ A [ NAT μ a o (FMap T (NAT η a )) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
3
|
110 Lemma6 = \m -> IsMonad.unity2 ( isMonad m )
|
|
111
|
|
112 -- T = M x A
|
0
|
113 -- nat of η
|
|
114 -- g ○ f = μ(c) T(g) f
|
|
115 -- h ○ (g ○ f) = (h ○ g) ○ f
|
|
116 -- η(b) ○ f = f
|
|
117 -- f ○ η(a) = f
|
|
118
|
4
|
119 record Kleisli { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ )
|
|
120 ( T : Functor A A )
|
5
|
121 ( η : NNAT A A identityFunctor T )
|
|
122 ( μ : NNAT A A (T ○ T) T )
|
4
|
123 ( M : Monad A T η μ ) : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
5
|
124 monad : Monad A T η μ
|
|
125 monad = M
|
4
|
126 join : { a b : Obj A } -> ( c : Obj A ) ->
|
|
127 ( Hom A b ( FObj T c )) -> ( Hom A a ( FObj T b)) -> Hom A a ( FObj T c )
|
5
|
128 join c g f = A [ NAT μ c o A [ FMap T g o f ] ]
|
|
129
|
|
130 open import Relation.Binary
|
|
131 open import Relation.Binary.Core
|
4
|
132
|
|
133 open Kleisli
|
|
134 Lemma7 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
3
|
135 { T : Functor A A }
|
5
|
136 { η : NNAT A A identityFunctor T }
|
|
137 { μ : NNAT A A (T ○ T) T }
|
|
138 { a b : Obj A }
|
|
139 { f : Hom A a ( FObj T b) }
|
|
140 { M : Monad A T η μ }
|
|
141 ( K : Kleisli A T η μ M)
|
|
142 -> A [ join K b (NAT η b) f ≈ f ]
|
6
|
143 Lemma7 k = {!!}
|
5
|
144
|
|
145 Lemma8 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
146 { T : Functor A A }
|
|
147 { η : NNAT A A identityFunctor T }
|
|
148 { μ : NNAT A A (T ○ T) T }
|
4
|
149 { a b : Obj A }
|
|
150 { f : Hom A a ( FObj T b) }
|
|
151 { M : Monad A T η μ }
|
|
152 ( K : Kleisli A T η μ M)
|
5
|
153 -> A [ join K b f (NAT η a) ≈ f ]
|
6
|
154 Lemma8 k = ?
|
5
|
155
|
|
156 Lemma9 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
157 { T : Functor A A }
|
|
158 { η : NNAT A A identityFunctor T }
|
|
159 { μ : NNAT A A (T ○ T) T }
|
|
160 { a b c d : Obj A }
|
|
161 { f : Hom A a ( FObj T b) }
|
|
162 { g : Hom A b ( FObj T c) }
|
|
163 { h : Hom A c ( FObj T d) }
|
|
164 { M : Monad A T η μ }
|
|
165 ( K : Kleisli A T η μ M)
|
|
166 -> A [ join K d h (join K c g f) ≈ join K d ( join K d h g) f ]
|
6
|
167 Lemma9 k = {!!}
|
5
|
168
|
4
|
169
|
3
|
170
|
|
171
|
|
172
|
|
173 -- Kleisli :
|
|
174 -- Kleisli = record { Hom =
|
|
175 -- ; Hom = _⟶_
|
|
176 -- ; Id = IdProd
|
|
177 -- ; _o_ = _∘_
|
|
178 -- ; _≈_ = _≈_
|
|
179 -- ; isCategory = record { isEquivalence = record { refl = λ {φ} → ≈-refl {φ = φ}
|
|
180 -- ; sym = λ {φ ψ} → ≈-symm {φ = φ} {ψ}
|
|
181 -- ; trans = λ {φ ψ σ} → ≈-trans {φ = φ} {ψ} {σ}
|
|
182 -- }
|
|
183 -- ; identityL = identityL
|
|
184 -- ; identityR = identityR
|
|
185 -- ; o-resp-≈ = o-resp-≈
|
|
186 -- ; associative = associative
|
|
187 -- }
|
|
188 -- }
|