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
|
|
29 record IsNTrans {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (D : Category c₁ c₂ ℓ) (C : Category c₁′ c₂′ ℓ′)
|
|
30 ( F G : Functor D C )
|
|
31 (Trans : (A : Obj D) → Hom C (FObj F A) (FObj G A))
|
|
32 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
33 field
|
|
34 naturality : {a b : Obj D} {f : Hom D a b}
|
|
35 → C [ C [ ( FMap G f ) o ( Trans a ) ] ≈ C [ (Trans b ) o (FMap F f) ] ]
|
|
36 -- uniqness : {d : Obj D}
|
3
|
37 -- → C [ Trans d ≈ Trans d ]
|
0
|
38
|
|
39
|
|
40 record NTrans {c₁ c₂ ℓ c₁′ c₂′ ℓ′ : Level} (domain : Category c₁ c₂ ℓ) (codomain : Category c₁′ c₂′ ℓ′) (F G : Functor domain codomain )
|
|
41 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ ⊔ c₁′ ⊔ c₂′ ⊔ ℓ′)) where
|
|
42 field
|
|
43 Trans : (A : Obj domain) → Hom codomain (FObj F A) (FObj G A)
|
|
44 isNTrans : IsNTrans domain codomain F G Trans
|
|
45
|
|
46 open NTrans
|
1
|
47 Lemma2 : {c₁ c₂ l : Level} {A : Category c₁ c₂ l} {F G : Functor A A}
|
|
48 -> (μ : NTrans A A F G) -> {a b : Obj A} { f : Hom A a b }
|
|
49 -> A [ A [ FMap G f o Trans μ a ] ≈ A [ Trans μ b o FMap F f ] ]
|
0
|
50 Lemma2 = \n -> IsNTrans.naturality ( isNTrans n )
|
|
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 )
|
|
62 ( η : NTrans A A identityFunctor T )
|
|
63 ( μ : NTrans A A (T ○ T) T)
|
|
64 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
65 field
|
3
|
66 assoc : {a : Obj A} -> A [ A [ Trans μ a o Trans μ ( FObj T a ) ] ≈ A [ Trans μ a o FMap T (Trans μ a) ] ]
|
|
67 unity1 : {a : Obj A} -> A [ A [ Trans μ a o Trans η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
|
68 unity2 : {a : Obj A} -> A [ A [ Trans μ a o (FMap T (Trans η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
0
|
69
|
1
|
70 record Monad {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) (T : Functor A A) (η : NTrans A A identityFunctor T) (μ : NTrans A A (T ○ T) T)
|
|
71 : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
72 field
|
|
73 isMonad : IsMonad A T η μ
|
0
|
74
|
2
|
75 open Monad
|
|
76 Lemma3 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
77 { T : Functor A A }
|
|
78 { η : NTrans A A identityFunctor T }
|
|
79 { μ : NTrans A A (T ○ T) T }
|
|
80 { a : Obj A } ->
|
|
81 ( M : Monad A T η μ )
|
|
82 -> A [ A [ Trans μ a o Trans μ ( FObj T a ) ] ≈ A [ Trans μ a o FMap T (Trans μ a) ] ]
|
|
83 Lemma3 = \m -> IsMonad.assoc ( isMonad m )
|
|
84
|
|
85
|
|
86 Lemma4 : {c₁ c₂ ℓ : Level} (A : Category c₁ c₂ ℓ) {a b : Obj A } { f : Hom A a b}
|
|
87 -> A [ A [ Id {_} {_} {_} {A} b o f ] ≈ f ]
|
|
88 Lemma4 = \a -> IsCategory.identityL ( Category.isCategory a )
|
0
|
89
|
3
|
90 Lemma5 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
91 { T : Functor A A }
|
|
92 { η : NTrans A A identityFunctor T }
|
|
93 { μ : NTrans A A (T ○ T) T }
|
|
94 { a : Obj A } ->
|
|
95 ( M : Monad A T η μ )
|
|
96 -> A [ A [ Trans μ a o Trans η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
|
97 Lemma5 = \m -> IsMonad.unity1 ( isMonad m )
|
|
98
|
|
99 Lemma6 : {c₁ c₂ ℓ : Level} {A : Category c₁ c₂ ℓ}
|
|
100 { T : Functor A A }
|
|
101 { η : NTrans A A identityFunctor T }
|
|
102 { μ : NTrans A A (T ○ T) T }
|
|
103 { a : Obj A } ->
|
|
104 ( M : Monad A T η μ )
|
|
105 -> A [ A [ Trans μ a o (FMap T (Trans η a )) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
|
|
106 Lemma6 = \m -> IsMonad.unity2 ( isMonad m )
|
|
107
|
|
108 -- T = M x A
|
|
109
|
|
110 -- open import Data.Product -- renaming (_×_ to _*_)
|
|
111
|
|
112 -- MonoidalMonad :
|
|
113 -- MonoidalMonad = record { Obj = M × A
|
|
114 -- ; Hom = _⟶_
|
|
115 -- ; Id = IdProd
|
|
116 -- ; _o_ = _∘_
|
|
117 -- ; _≈_ = _≈_
|
|
118 -- ; isCategory = record { isEquivalence = record { refl = λ {φ} → ≈-refl {φ = φ}
|
|
119 -- ; sym = λ {φ ψ} → ≈-symm {φ = φ} {ψ}
|
|
120 -- ; trans = λ {φ ψ σ} → ≈-trans {φ = φ} {ψ} {σ}
|
|
121 -- }
|
|
122 -- ; identityL = identityL
|
|
123 -- ; identityR = identityR
|
|
124 -- ; o-resp-≈ = o-resp-≈
|
|
125 -- ; associative = associative
|
|
126 -- }
|
|
127 -- }
|
|
128
|
|
129
|
0
|
130 -- nat of η
|
|
131
|
|
132
|
|
133 -- g ○ f = μ(c) T(g) f
|
|
134 -- h ○ (g ○ f) = (h ○ g) ○ f
|
|
135
|
|
136 -- η(b) ○ f = f
|
|
137 -- f ○ η(a) = f
|
|
138
|
|
139
|
3
|
140 record Kleisli { c₁ c₂ ℓ : Level} { A : Category c₁ c₂ ℓ }
|
|
141 { T : Functor A A }
|
|
142 { η : NTrans A A identityFunctor T }
|
|
143 { μ : NTrans A A (T ○ T) T }
|
|
144 { M : Monad A T η μ } : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
|
|
145 infix 9 _*_
|
|
146 _*_ : { a b c : Obj A } ->
|
|
147 ( Hom A b ( FObj T c )) -> ( Hom A a ( FObj T b)) -> Hom A a ( FObj T c )
|
|
148 g * f = A [ Trans μ ({!!} (Category.cod A g)) o A [ FMap T g o f ] ]
|
|
149
|
|
150
|
|
151
|
|
152 -- Kleisli :
|
|
153 -- Kleisli = record { Hom =
|
|
154 -- ; Hom = _⟶_
|
|
155 -- ; Id = IdProd
|
|
156 -- ; _o_ = _∘_
|
|
157 -- ; _≈_ = _≈_
|
|
158 -- ; isCategory = record { isEquivalence = record { refl = λ {φ} → ≈-refl {φ = φ}
|
|
159 -- ; sym = λ {φ ψ} → ≈-symm {φ = φ} {ψ}
|
|
160 -- ; trans = λ {φ ψ σ} → ≈-trans {φ = φ} {ψ} {σ}
|
|
161 -- }
|
|
162 -- ; identityL = identityL
|
|
163 -- ; identityR = identityR
|
|
164 -- ; o-resp-≈ = o-resp-≈
|
|
165 -- ; associative = associative
|
|
166 -- }
|
|
167 -- }
|