annotate monoid-monad.agda @ 143:bbaaca9b21ce

on going ...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 13 Aug 2013 18:07:27 +0900
parents 94796ddb9570
children 0948df8c88b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
129
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 open import Category -- https://github.com/konn/category-agda
130
5f331dfc000b remove Kleisli record
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
2 open import Category.Monoid
5f331dfc000b remove Kleisli record
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
3 open import Algebra
129
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Level
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
5 module monoid-monad {c c₁ c₂ ℓ : Level} { Mono : Monoid c ℓ} where
130
5f331dfc000b remove Kleisli record
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
6
142
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
7 open import Algebra.Structures
129
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import HomReasoning
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import cat-utility
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Category.Cat
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Category.Sets
138
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
12 open import Data.Product
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
13 open import Relation.Binary.Core
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
14 open import Relation.Binary
131
eb7ca6b9d327 trying..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
15
138
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
16 open Monoid
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
17
139
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
18 -- T : A → (M x A)
134
de1c3443f10d M x A done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
19
138
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
20 T : Functor (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ })
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
21 T = record {
139
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
22 FObj = \a → (Carrier Mono) × a
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
23 ; FMap = \f → map ( \x → x ) f
138
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
24 ; isFunctor = record {
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
25 identity = IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets ))
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
26 ; distr = (IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets )))
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
27 ; ≈-cong = cong1
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
28 }
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
29 } where
139
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
30 cong1 : {ℓ′ : Level} → {a b : Set ℓ′} { f g : Hom (Sets {ℓ′}) a b} →
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
31 Sets [ f ≈ g ] → Sets [ map (λ x → x) f ≈ map (λ x → x) g ]
138
293e3e8c43dd T as Sets -> Sets
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
32 cong1 _≡_.refl = _≡_.refl
129
fdf89038556a monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
139
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
34 Lemma-MM1 : {a b : Obj Sets} {f : Hom Sets a b} →
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
35 Sets [ Sets [ Functor.FMap T f o (λ x → ε Mono , x) ] ≈
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
36 Sets [ (λ x → ε Mono , x) o f ] ]
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
37 Lemma-MM1 {a} {b} {f} = let open ≈-Reasoning (Sets) renaming ( _o_ to _*_ ) in
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
38 begin
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
39 Functor.FMap T f o (λ x → ε Mono , x)
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
40 ≈⟨⟩
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
41 (λ x → ε Mono , x) o f
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
42
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
43
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
44 -- a → (ε,a)
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
45 η : NTrans (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) identityFunctor T
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
46 η = record {
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
47 TMap = \a → \(x : a) → ( ε Mono , x ) ;
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
48 isNTrans = record {
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
49 commute = \{a} {b} {f} → IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets ))
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
50 }
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
51 }
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
52
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
53 -- (m,(m',a)) → (m*m,a)
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
54
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
55 open Functor
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
56
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
57 muMap : (a : Obj Sets ) → FObj T ( FObj T a ) → Σ (Carrier Mono) (λ x → a )
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
58 muMap a ( m , ( m' , x ) ) = ( _∙_ Mono m m' , x )
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
59
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
60 Lemma-MM2 : {a b : Obj Sets} {f : Hom Sets a b} →
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
61 Sets [ Sets [ FMap T f o (λ x → muMap a x) ] ≈
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
62 Sets [ (λ x → muMap b x) o FMap (T ○ T) f ] ]
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
63 Lemma-MM2 {a} {b} {f} = let open ≈-Reasoning (Sets) renaming ( _o_ to _*_ ) in
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
64 begin
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
65 FMap T f o (λ x → muMap a x)
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
66 ≈⟨⟩
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
67 (λ x → muMap b x) o FMap (T ○ T) f
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
68
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
69
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
70 μ : NTrans (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) ( T ○ T ) T
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
71 μ = record {
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
72 TMap = \a → \x → muMap a x ;
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
73 isNTrans = record {
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
74 commute = \{a} {b} {f} → IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets ))
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
75 }
17f45f909770 η and μ defined.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
76 }
141
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
77
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
78 open NTrans
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
79
143
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
80 --Lemma-MM32 : ∀{ℓ} {a : Set ℓ } -> {f g : a -> a } -> {x : a } -> ( f ≡ g ) -> ( ( λ x → f x ) ≡ ( λ x → g x ) )
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
81 --Lemma-MM32 eq = cong ( \f -> \x -> f x ) eq
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
82
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
83 --Lemma-MM31 : ( a : Obj ( Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) ) -> {x : FObj T a } → (((Mono ∙ ε Mono) (proj₁ x) , proj₂ x ) ≡ x )
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
84 --Lemma-MM31 a = {!!}
142
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
85
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
86 Lemma-MM33 : {a : Level} {b : Level} {A : Set a} {B : A → Set b} {x : Σ A B } → (((proj₁ x) , proj₂ x ) ≡ x )
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
87 Lemma-MM33 = _≡_.refl
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
88
143
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
89 Lemma-M-34 : { x : Carrier Mono } -> _≈_ Mono ((_∙_ Mono (ε Mono) x)) x
bbaaca9b21ce on going ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 142
diff changeset
90 Lemma-M-34 {x} = ( proj₁ ( IsMonoid.identity ( isMonoid Mono )) ) x
141
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
91
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
92 MonoidMonad : Monad (Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }) T η μ
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
93 MonoidMonad = record {
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
94 isMonad = record {
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
95 unity1 = \{a} -> Lemma-MM3 {a} ;
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
96 unity2 = Lemma-MM4 ;
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
97 assoc = Lemma-MM5
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
98 }
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
99 } where
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
100 A = Sets {c ⊔ c₁ ⊔ c₂ ⊔ ℓ }
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
101 Lemma-MM3 : {a : Obj A} → A [ A [ TMap μ a o TMap η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ]
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
102 Lemma-MM3 {a} = let open ≈-Reasoning (Sets) renaming ( _o_ to _*_ ) in
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
103 begin
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
104 TMap μ a o TMap η ( FObj T a )
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
105 ≈⟨⟩
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
106 ( λ x → ((Mono ∙ ε Mono) (proj₁ x) , proj₂ x ))
142
94796ddb9570 on going...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
107 ≈⟨ {!!} ⟩
141
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
108 ( λ x → x )
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
109 ≈⟨⟩
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
110 Id {_} {_} {_} {A} (FObj T a)
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
111
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
112 Lemma-MM4 : {a : Obj A} → A [ A [ TMap μ a o (FMap T (TMap η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ]
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
113 Lemma-MM4 = {!!}
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
114 Lemma-MM5 : {a : Obj A} → A [ A [ TMap μ a o TMap μ ( FObj T a ) ] ≈ A [ TMap μ a o FMap T (TMap μ a) ] ]
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
115 Lemma-MM5 = {!!}
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
116
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
117
4a362cf32a74 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
118