Mercurial > hg > Members > kono > Proof > category
annotate applicative.agda @ 768:9bcdbfbaaa39
clean up
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Dec 2017 10:25:59 +0900 |
parents | monoidal.agda@c30ca91f3a76 |
children | 43138aead09b |
rev | line source |
---|---|
696
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 open import Level |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 open import Category |
768 | 3 module applicative where |
696
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 open import Data.Product renaming (_×_ to _*_) |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 open import Category.Constructions.Product |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 open import HomReasoning |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 open import cat-utility |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 open import Relation.Binary.Core |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 open import Relation.Binary |
768 | 11 open import monoidal |
12 open import Category.Sets | |
13 import Relation.Binary.PropositionalEquality | |
696
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 open Functor |
10ccac3bc285
Monoidal category and applicative functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
705
73a998711118
add Applicative and HaskellMonoidal Functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
17 |
720 | 18 _・_ : {c₁ : Level} { a b c : Obj (Sets {c₁} ) } → (b → c) → (a → b) → a → c |
19 _・_ f g = λ x → f ( g x ) | |
713 | 20 |
766 | 21 record IsApplicative {c₁ : Level} ( F : Functor (Sets {c₁}) (Sets {c₁}) ) |
22 ( pure : {a : Obj Sets} → Hom Sets a ( FObj F a ) ) | |
23 ( _<*>_ : {a b : Obj Sets} → FObj F ( a → b ) → FObj F a → FObj F b ) | |
713 | 24 : Set (suc (suc c₁)) where |
25 field | |
766 | 26 identity : { a : Obj Sets } { u : FObj F a } → pure ( id1 Sets a ) <*> u ≡ u |
27 composition : { a b c : Obj Sets } { u : FObj F ( b → c ) } { v : FObj F (a → b ) } { w : FObj F a } | |
713 | 28 → (( pure _・_ <*> u ) <*> v ) <*> w ≡ u <*> (v <*> w) |
29 homomorphism : { a b : Obj Sets } { f : Hom Sets a b } { x : a } → pure f <*> pure x ≡ pure (f x) | |
766 | 30 interchange : { a b : Obj Sets } { u : FObj F ( a → b ) } { x : a } → u <*> pure x ≡ pure (λ f → f x) <*> u |
730 | 31 -- from http://www.staff.city.ac.uk/~ross/papers/Applicative.pdf |
713 | 32 |
33 record Applicative {c₁ : Level} ( F : Functor (Sets {c₁}) (Sets {c₁}) ) | |
705
73a998711118
add Applicative and HaskellMonoidal Functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
34 : Set (suc (suc c₁)) where |
73a998711118
add Applicative and HaskellMonoidal Functor
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
704
diff
changeset
|
35 field |
713 | 36 pure : {a : Obj Sets} → Hom Sets a ( FObj F a ) |
37 <*> : {a b : Obj Sets} → FObj F ( a → b ) → FObj F a → FObj F b | |
766 | 38 isApplicative : IsApplicative F pure <*> |
713 | 39 |
730 | 40 ------ |
41 -- | |
42 -- Appllicative Functor is a Monoidal Functor | |
43 -- | |
44 | |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
45 Applicative→Monoidal : {c : Level} ( F : Functor (Sets {c}) (Sets {c}) ) → (mf : Applicative F ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
46 → IsApplicative F ( Applicative.pure mf ) ( Applicative.<*> mf ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
47 → MonoidalFunctor {_} {c} {_} {Sets} {Sets} MonoidalSets MonoidalSets |
727
ea84cc6c1797
monoidal functor and applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
48 Applicative→Monoidal {l} F mf ismf = record { |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
49 MF = F |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
50 ; ψ = λ x → unit |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
51 ; isMonodailFunctor = record { |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
52 φab = record { TMap = λ x → φ ; isNTrans = record { commute = comm0 } } |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
53 ; associativity = λ {a b c} → comm1 {a} {b} {c} |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
54 ; unitarity-idr = λ {a b} → comm2 {a} {b} |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
55 ; unitarity-idl = λ {a b} → comm3 {a} {b} |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
56 } |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
57 } where |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
58 open Monoidal |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
59 open IsMonoidal hiding ( _■_ ; _□_ ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
60 M = MonoidalSets |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
61 isM = Monoidal.isMonoidal MonoidalSets |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
62 unit = Applicative.pure mf OneObj |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
63 _⊗_ : (x y : Obj Sets ) → Obj Sets |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
64 _⊗_ x y = (IsMonoidal._□_ (Monoidal.isMonoidal M) ) x y |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
65 _□_ : {a b c d : Obj Sets } ( f : Hom Sets a c ) ( g : Hom Sets b d ) → Hom Sets ( a ⊗ b ) ( c ⊗ d ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
66 _□_ f g = FMap (m-bi M) ( f , g ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
67 φ : {x : Obj (Sets × Sets) } → Hom Sets (FObj (Functor● Sets Sets MonoidalSets F) x) (FObj (Functor⊗ Sets Sets MonoidalSets F) x) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
68 φ x = Applicative.<*> mf (FMap F (λ j k → (j , k)) (proj₁ x )) (proj₂ x) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
69 _<*>_ : {a b : Obj Sets} → FObj F ( a → b ) → FObj F a → FObj F b |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
70 _<*>_ = Applicative.<*> mf |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
71 left : {a b : Obj Sets} → {x y : FObj F ( a → b )} → {h : FObj F a } → ( x ≡ y ) → x <*> h ≡ y <*> h |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
72 left {_} {_} {_} {_} {h} eq = ≡-cong ( λ k → k <*> h ) eq |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
73 right : {a b : Obj Sets} → {h : FObj F ( a → b )} → {x y : FObj F a } → ( x ≡ y ) → h <*> x ≡ h <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
74 right {_} {_} {h} {_} {_} eq = ≡-cong ( λ k → h <*> k ) eq |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
75 id : { a : Obj Sets } → a → a |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
76 id x = x |
720 | 77 pure : {a : Obj Sets } → Hom Sets a ( FObj F a ) |
78 pure a = Applicative.pure mf a | |
725 | 79 -- special case |
80 F→pureid : {a b : Obj Sets } → (x : FObj F a ) → FMap F id x ≡ pure id <*> x | |
81 F→pureid {a} {b} x = sym ( begin | |
722
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
82 pure id <*> x |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
83 ≡⟨ IsApplicative.identity ismf ⟩ |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
84 x |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
85 ≡⟨ ≡-cong ( λ k → k x ) (sym ( IsFunctor.identity (isFunctor F ) )) ⟩ FMap F id x |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
86 ∎ ) |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
87 where |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
88 open Relation.Binary.PropositionalEquality |
69f01b82dfc9
uniquness of functor fmap
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
721
diff
changeset
|
89 open Relation.Binary.PropositionalEquality.≡-Reasoning |
725 | 90 F→pure : {a b : Obj Sets } → { f : a → b } → {x : FObj F a } → FMap F f x ≡ pure f <*> x |
91 F→pure {a} {b} {f} {x} = sym ( begin | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
92 pure f <*> x |
731
117e5b392673
Generalize Free Theorem
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
730
diff
changeset
|
93 ≡⟨ ≡-cong ( λ k → k x ) (UniquenessOfFunctor Sets Sets F ( λ f x → pure f <*> x ) ( extensionality Sets ( λ x → IsApplicative.identity ismf ))) ⟩ |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
94 FMap F f x |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
95 ∎ ) |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
96 where |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
97 open Relation.Binary.PropositionalEquality |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
98 open Relation.Binary.PropositionalEquality.≡-Reasoning |
725 | 99 p*p : { a b : Obj Sets } { f : Hom Sets a b } { x : a } → pure f <*> pure x ≡ pure (f x) |
100 p*p = IsApplicative.homomorphism ismf | |
101 comp = IsApplicative.composition ismf | |
102 inter = IsApplicative.interchange ismf | |
729 | 103 pureAssoc : {a b c : Obj Sets } ( f : b → c ) ( g : a → b ) ( h : FObj F a ) → pure f <*> ( pure g <*> h ) ≡ pure ( f ・ g ) <*> h |
104 pureAssoc f g h = trans ( trans (sym comp) (left (left p*p) )) ( left p*p ) | |
105 where | |
106 open Relation.Binary.PropositionalEquality | |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
107 comm00 : {a b : Obj (Sets × Sets)} { f : Hom (Sets × Sets) a b} (x : ( FObj F (proj₁ a) * FObj F (proj₂ a)) ) → |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
108 (Sets [ FMap (Functor⊗ Sets Sets MonoidalSets F) f o φ ]) x ≡ (Sets [ φ o FMap (Functor● Sets Sets MonoidalSets F) f ]) x |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
109 comm00 {a} {b} {(f , g)} (x , y) = begin |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
110 ( FMap (Functor⊗ Sets Sets MonoidalSets F) (f , g) ) ( φ (x , y) ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
111 ≡⟨⟩ |
725 | 112 FMap F (λ xy → f (proj₁ xy) , g (proj₂ xy)) ((FMap F (λ j k → j , k) x) <*> y) |
113 ≡⟨⟩ | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
114 FMap F (map f g) ((FMap F (λ j k → j , k) x) <*> y) |
725 | 115 ≡⟨ F→pure ⟩ |
116 (pure (map f g) <*> (FMap F (λ j k → j , k) x <*> y)) | |
117 ≡⟨ right ( left F→pure ) ⟩ | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
118 (pure (map f g)) <*> ((pure (λ j k → j , k) <*> x) <*> y) |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
119 ≡⟨ sym ( IsApplicative.composition ismf ) ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
120 (( pure _・_ <*> (pure (map f g))) <*> (pure (λ j k → j , k) <*> x)) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
121 ≡⟨ left ( sym ( IsApplicative.composition ismf )) ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
122 ((( pure _・_ <*> (( pure _・_ <*> (pure (map f g))))) <*> pure (λ j k → j , k)) <*> x) <*> y |
725 | 123 ≡⟨ trans ( trans (left ( left (left (right p*p )))) ( left ( left ( left p*p)))) (left (left p*p)) ⟩ |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
124 (pure (( _・_ (( _・_ ((map f g))))) (λ j k → j , k)) <*> x) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
125 ≡⟨⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
126 (pure (λ j k → f j , g k) <*> x) <*> y |
725 | 127 ≡⟨⟩ |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
128 ( pure ((_・_ (( _・_ ( ( λ h → h g ))) ( _・_ ))) ((λ j k → f j , k))) <*> x ) <*> y |
725 | 129 ≡⟨ sym ( trans (left (left (left p*p))) (left ( left p*p)) ) ⟩ |
130 ((((pure _・_ <*> pure ((λ h → h g) ・ _・_)) <*> pure (λ j k → f j , k)) <*> x) <*> y) | |
131 ≡⟨ sym (trans ( left ( left ( left (right (left p*p) )))) (left ( left (left (right p*p ))))) ⟩ | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
132 (((pure _・_ <*> (( pure _・_ <*> ( pure ( λ h → h g ))) <*> ( pure _・_ ))) <*> (pure (λ j k → f j , k))) <*> x ) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
133 ≡⟨ left ( ( IsApplicative.composition ismf )) ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
134 ((( pure _・_ <*> ( pure ( λ h → h g ))) <*> ( pure _・_ )) <*> (pure (λ j k → f j , k) <*> x )) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
135 ≡⟨ left (IsApplicative.composition ismf ) ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
136 ( pure ( λ h → h g ) <*> ( pure _・_ <*> (pure (λ j k → f j , k) <*> x )) ) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
137 ≡⟨ left (sym (IsApplicative.interchange ismf )) ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
138 (( pure _・_ <*> (pure (λ j k → f j , k) <*> x )) <*> pure g) <*> y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
139 ≡⟨ IsApplicative.composition ismf ⟩ |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
140 (pure (λ j k → f j , k) <*> x) <*> (pure g <*> y) |
725 | 141 ≡⟨ sym ( trans (left F→pure ) ( right F→pure ) ) ⟩ |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
142 (FMap F (λ j k → f j , k) x) <*> (FMap F g y) |
720 | 143 ≡⟨ ≡-cong ( λ k → k x <*> (FMap F g y)) ( IsFunctor.distr (isFunctor F )) ⟩ |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
144 (FMap F (λ j k → j , k) (FMap F f x)) <*> (FMap F g y) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
145 ≡⟨⟩ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
146 φ ( ( FMap (Functor● Sets Sets MonoidalSets F) (f , g) ) ( x , y ) ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
147 ∎ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
148 where |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
149 open Relation.Binary.PropositionalEquality |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
150 open Relation.Binary.PropositionalEquality.≡-Reasoning |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
151 comm0 : {a b : Obj (Sets × Sets)} { f : Hom (Sets × Sets) a b} → Sets [ Sets [ FMap (Functor⊗ Sets Sets MonoidalSets F) f o φ ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
152 ≈ Sets [ φ o FMap (Functor● Sets Sets MonoidalSets F) f ] ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
153 comm0 {a} {b} {f} = extensionality Sets ( λ (x : ( FObj F (proj₁ a) * FObj F (proj₂ a)) ) → comm00 x ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
154 comm10 : {a b c : Obj Sets} → (x : ((FObj F a ⊗ FObj F b) ⊗ FObj F c) ) → (Sets [ φ o Sets [ id1 Sets (FObj F a) □ φ o Iso.≅→ (mα-iso isM) ] ]) x ≡ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
155 (Sets [ FMap F (Iso.≅→ (mα-iso isM)) o Sets [ φ o φ □ id1 Sets (FObj F c) ] ]) x |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
156 comm10 {x} {y} {f} ((a , b) , c ) = begin |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
157 φ (( id □ φ ) ( ( Iso.≅→ (mα-iso isM) ) ((a , b) , c))) |
720 | 158 ≡⟨⟩ |
159 (FMap F (λ j k → j , k) a) <*> ( (FMap F (λ j k → j , k) b) <*> c) | |
726 | 160 ≡⟨ trans (left F→pure) (right (left F→pure) ) ⟩ |
725 | 161 (pure (λ j k → j , k) <*> a) <*> ( (pure (λ j k → j , k) <*> b) <*> c) |
726 | 162 ≡⟨ sym comp ⟩ |
725 | 163 ( ( pure _・_ <*> (pure (λ j k → j , k) <*> a)) <*> (pure (λ j k → j , k) <*> b)) <*> c |
726 | 164 ≡⟨ sym ( left comp ) ⟩ |
725 | 165 (( ( pure _・_ <*> ( pure _・_ <*> (pure (λ j k → j , k) <*> a))) <*> (pure (λ j k → j , k))) <*> b) <*> c |
726 | 166 ≡⟨ sym ( left ( left ( left (right comp )))) ⟩ |
725 | 167 (( ( pure _・_ <*> (( (pure _・_ <*> pure _・_ ) <*> (pure (λ j k → j , k))) <*> a)) <*> (pure (λ j k → j , k))) <*> b) <*> c |
726 | 168 ≡⟨ trans (left ( left (left ( right (left ( left p*p )))))) (left ( left ( left (right (left p*p))))) ⟩ |
725 | 169 (( ( pure _・_ <*> ((pure ((_・_ ( _・_ )) ((λ j k → j , k)))) <*> a)) <*> (pure (λ j k → j , k))) <*> b) <*> c |
726 | 170 ≡⟨ sym (left ( left ( left comp ) )) ⟩ |
725 | 171 (((( ( pure _・_ <*> (pure _・_ )) <*> (pure ((_・_ ( _・_ )) ((λ j k → j , k))))) <*> a) <*> (pure (λ j k → j , k))) <*> b) <*> c |
726 | 172 ≡⟨ trans (left ( left ( left (left (left p*p))))) (left ( left ( left (left p*p )))) ⟩ |
725 | 173 ((((pure ( ( _・_ (_・_ )) (((_・_ ( _・_ )) ((λ j k → j , k)))))) <*> a) <*> (pure (λ j k → j , k))) <*> b) <*> c |
174 ≡⟨⟩ | |
175 ((((pure (λ f g x y → f , g x y)) <*> a) <*> (pure (λ j k → j , k))) <*> b) <*> c | |
726 | 176 ≡⟨ left ( left inter ) ⟩ |
725 | 177 (((pure (λ f → f (λ j k → j , k))) <*> ((pure (λ f g x y → f , g x y)) <*> a) ) <*> b) <*> c |
726 | 178 ≡⟨ sym ( left ( left comp )) ⟩ |
725 | 179 (((( pure _・_ <*> (pure (λ f → f (λ j k → j , k)))) <*> (pure (λ f g x y → f , g x y))) <*> a ) <*> b) <*> c |
726 | 180 ≡⟨ trans (left ( left (left (left p*p) ))) (left (left (left p*p ) )) ⟩ |
725 | 181 ((pure (( _・_ (λ f → f (λ j k → j , k))) (λ f g x y → f , g x y)) <*> a ) <*> b) <*> c |
182 ≡⟨⟩ | |
183 (((pure (λ f g h → f , g , h)) <*> a) <*> b) <*> c | |
184 ≡⟨⟩ | |
185 ((pure ((_・_ ((_・_ ((_・_ ( (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))))))) | |
186 (( _・_ ( _・_ ((λ j k → j , k)))) (λ j k → j , k))) <*> a) <*> b) <*> c | |
726 | 187 ≡⟨ sym (trans ( left ( left ( left (left (right (right p*p))) ) )) (trans (left (left( left (left (right p*p))))) |
188 (trans (left (left (left (left p*p)))) (trans ( left (left (left (right (left (right p*p )))))) | |
189 (trans (left (left (left (right (left p*p))))) (trans (left (left (left (right p*p)))) (left (left (left p*p)))) ) ) ) | |
190 ) ) ⟩ | |
725 | 191 ((((pure _・_ <*> ((pure _・_ <*> ((pure _・_ <*> ( pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))))))) <*> |
192 (( pure _・_ <*> ( pure _・_ <*> (pure (λ j k → j , k)))) <*> pure (λ j k → j , k))) <*> a) <*> b) <*> c | |
726 | 193 ≡⟨ left (left comp ) ⟩ |
725 | 194 (((pure _・_ <*> ((pure _・_ <*> ( pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))))) <*> |
195 ((( pure _・_ <*> ( pure _・_ <*> (pure (λ j k → j , k)))) <*> pure (λ j k → j , k)) <*> a)) <*> b) <*> c | |
726 | 196 ≡⟨ left comp ⟩ |
725 | 197 ((pure _・_ <*> ( pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))) <*> |
198 (((( pure _・_ <*> ( pure _・_ <*> (pure (λ j k → j , k)))) <*> pure (λ j k → j , k)) <*> a) <*> b)) <*> c | |
726 | 199 ≡⟨ left ( right (left comp )) ⟩ |
725 | 200 ((pure _・_ <*> ( pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))) <*> |
201 ((( pure _・_ <*> (pure (λ j k → j , k))) <*> (pure (λ j k → j , k) <*> a)) <*> b)) <*> c | |
726 | 202 ≡⟨ left ( right comp ) ⟩ |
725 | 203 ((pure _・_ <*> ( pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc))) <*> |
204 (pure (λ j k → j , k) <*> ( (pure (λ j k → j , k) <*> a) <*> b))) <*> c | |
726 | 205 ≡⟨ comp ⟩ |
725 | 206 pure (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc) <*> ( (pure (λ j k → j , k) <*> ( (pure (λ j k → j , k) <*> a) <*> b)) <*> c) |
726 | 207 ≡⟨ sym ( trans ( trans F→pure (right (left F→pure ))) ( right ( left (right (left F→pure ))))) ⟩ |
720 | 208 FMap F (λ abc → proj₁ (proj₁ abc) , proj₂ (proj₁ abc) , proj₂ abc) ( (FMap F (λ j k → j , k) ( (FMap F (λ j k → j , k) a) <*> b)) <*> c) |
209 ≡⟨⟩ | |
210 ( FMap F (Iso.≅→ (mα-iso isM))) (φ (( φ □ id1 Sets (FObj F f) ) ((a , b) , c))) | |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
211 ∎ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
212 where |
720 | 213 open Relation.Binary.PropositionalEquality |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
214 open Relation.Binary.PropositionalEquality.≡-Reasoning |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
215 comm1 : {a b c : Obj Sets} → Sets [ Sets [ φ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
216 o Sets [ (id1 Sets (FObj F a) □ φ ) o Iso.≅→ (mα-iso isM) ] ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
217 ≈ Sets [ FMap F (Iso.≅→ (mα-iso isM)) o Sets [ φ o (φ □ id1 Sets (FObj F c)) ] ] ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
218 comm1 {a} {b} {c} = extensionality Sets ( λ x → comm10 x ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
219 comm20 : {a b : Obj Sets} ( x : FObj F a * One ) → ( Sets [ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
220 FMap F (Iso.≅→ (mρ-iso isM)) o Sets [ φ o |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
221 FMap (m-bi MonoidalSets) (id1 Sets (FObj F a) , (λ _ → unit )) ] ] ) x ≡ Iso.≅→ (mρ-iso isM) x |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
222 comm20 {a} {b} (x , OneObj ) = begin |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
223 (FMap F (Iso.≅→ (mρ-iso isM))) ( φ (( FMap (m-bi MonoidalSets) (id1 Sets (FObj F a) , (λ _ → unit))) (x , OneObj) )) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
224 ≡⟨⟩ |
720 | 225 FMap F proj₁ ((FMap F (λ j k → j , k) x) <*> (pure OneObj)) |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
226 ≡⟨ ≡-cong ( λ k → FMap F proj₁ k) ( IsApplicative.interchange ismf ) ⟩ |
720 | 227 FMap F proj₁ ((pure (λ f → f OneObj)) <*> (FMap F (λ j k → j , k) x)) |
725 | 228 ≡⟨ ( trans F→pure (right ( right F→pure )) ) ⟩ |
229 pure proj₁ <*> ((pure (λ f → f OneObj)) <*> (pure (λ j k → j , k) <*> x)) | |
230 ≡⟨ sym ( right comp ) ⟩ | |
231 pure proj₁ <*> (((pure _・_ <*> (pure (λ f → f OneObj))) <*> pure (λ j k → j , k)) <*> x) | |
232 ≡⟨ sym comp ⟩ | |
233 ( ( pure _・_ <*> (pure proj₁ ) ) <*> ((pure _・_ <*> (pure (λ f → f OneObj))) <*> pure (λ j k → j , k))) <*> x | |
234 ≡⟨ trans ( trans ( trans ( left ( left p*p)) ( left ( right (left p*p) ))) (left (right p*p) ) ) (left p*p) ⟩ | |
727
ea84cc6c1797
monoidal functor and applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
235 pure ( ( _・_ (proj₁ {l} {l})) ((_・_ ((λ f → f OneObj))) (λ j k → j , k))) <*> x |
725 | 236 ≡⟨⟩ |
237 pure id <*> x | |
238 ≡⟨ IsApplicative.identity ismf ⟩ | |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
239 x |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
240 ≡⟨⟩ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
241 Iso.≅→ (mρ-iso isM) (x , OneObj) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
242 ∎ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
243 where |
725 | 244 open Relation.Binary.PropositionalEquality |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
245 open Relation.Binary.PropositionalEquality.≡-Reasoning |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
246 comm2 : {a b : Obj Sets} → Sets [ Sets [ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
247 FMap F (Iso.≅→ (mρ-iso isM)) o Sets [ φ o |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
248 FMap (m-bi MonoidalSets) (id1 Sets (FObj F a) , (λ _ → unit )) ] ] ≈ Iso.≅→ (mρ-iso isM) ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
249 comm2 {a} {b} = extensionality Sets ( λ x → comm20 {a} {b} x ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
250 comm30 : {a b : Obj Sets} ( x : One * FObj F b ) → ( Sets [ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
251 FMap F (Iso.≅→ (mλ-iso isM)) o Sets [ φ o |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
252 FMap (m-bi MonoidalSets) ((λ _ → unit ) , id1 Sets (FObj F b) ) ] ] ) x ≡ Iso.≅→ (mλ-iso isM) x |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
253 comm30 {a} {b} ( OneObj , x) = begin |
720 | 254 (FMap F (Iso.≅→ (mλ-iso isM))) ( φ ( unit , x ) ) |
255 ≡⟨⟩ | |
256 FMap F proj₂ ((FMap F (λ j k → j , k) (pure OneObj)) <*> x) | |
725 | 257 ≡⟨ ( trans F→pure (right ( left F→pure )) ) ⟩ |
258 pure proj₂ <*> ((pure (λ j k → j , k) <*> (pure OneObj)) <*> x) | |
259 ≡⟨ sym comp ⟩ | |
260 ((pure _・_ <*> (pure proj₂)) <*> (pure (λ j k → j , k) <*> (pure OneObj))) <*> x | |
261 ≡⟨ trans (trans (left (left p*p )) (left ( right p*p)) ) (left p*p) ⟩ | |
727
ea84cc6c1797
monoidal functor and applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
726
diff
changeset
|
262 pure ((_・_ (proj₂ {l}) )((λ (j : One {l}) (k : b ) → j , k) OneObj)) <*> x |
725 | 263 ≡⟨⟩ |
264 pure id <*> x | |
265 ≡⟨ IsApplicative.identity ismf ⟩ | |
720 | 266 x |
267 ≡⟨⟩ | |
268 Iso.≅→ (mλ-iso isM) ( OneObj , x ) | |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
269 ∎ |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
270 where |
725 | 271 open Relation.Binary.PropositionalEquality |
719
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
272 open Relation.Binary.PropositionalEquality.≡-Reasoning |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
273 comm3 : {a b : Obj Sets} → Sets [ Sets [ FMap F (Iso.≅→ (mλ-iso isM)) o |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
274 Sets [ φ o FMap (m-bi MonoidalSets) ((λ _ → unit ) , id1 Sets (FObj F b)) ] ] ≈ Iso.≅→ (mλ-iso isM) ] |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
275 comm3 {a} {b} = extensionality Sets ( λ x → comm30 {a} {b} x ) |
a017ed40dd77
Applicative law → Monoidal law begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
717
diff
changeset
|
276 |
730 | 277 ---- |
278 -- | |
279 -- Monoidal laws imples Applicative laws | |
280 -- | |
713 | 281 |
282 HaskellMonoidal→Applicative : {c₁ : Level} ( F : Functor (Sets {c₁}) (Sets {c₁}) ) | |
766 | 283 ( Mono : HaskellMonoidalFunctor F ) |
284 → Applicative F | |
285 HaskellMonoidal→Applicative {c₁} F Mono = record { | |
286 pure = pure ; | |
287 <*> = _<*>_ ; | |
288 isApplicative = record { | |
713 | 289 identity = identity |
290 ; composition = composition | |
291 ; homomorphism = homomorphism | |
292 ; interchange = interchange | |
293 } | |
766 | 294 } |
713 | 295 where |
766 | 296 unit : FObj F One |
297 unit = HaskellMonoidalFunctor.unit Mono | |
298 φ : {a b : Obj Sets} → Hom Sets ((FObj F a) * (FObj F b )) ( FObj F ( a * b ) ) | |
299 φ = HaskellMonoidalFunctor.φ Mono | |
300 mono : IsHaskellMonoidalFunctor F unit φ | |
301 mono = HaskellMonoidalFunctor.isHaskellMonoidalFunctor Mono | |
714 | 302 id : { a : Obj Sets } → a → a |
303 id x = x | |
713 | 304 isM : IsMonoidal (Sets {c₁}) One SetsTensorProduct |
305 isM = Monoidal.isMonoidal MonoidalSets | |
306 pure : {a : Obj Sets} → Hom Sets a ( FObj F a ) | |
307 pure {a} x = FMap F ( λ y → x ) (unit ) | |
308 _<*>_ : {a b : Obj Sets} → FObj F ( a → b ) → FObj F a → FObj F b | |
715 | 309 _<*>_ {a} {b} x y = FMap F ( λ r → ( proj₁ r ) ( proj₂ r ) ) (φ ( x , y )) |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
310 -- right does not work right it makes yellows. why? |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
311 -- right : {n : Level} { a b : Set n} → { x y : a } { h : a → b } → ( x ≡ y ) → h x ≡ h y |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
312 -- right {_} {_} {_} {_} {_} {h} eq = ≡-cong ( λ k → h k ) eq |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
313 left : {n : Level} { a b : Set n} → { x y : a → b } { h : a } → ( x ≡ y ) → x h ≡ y h |
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
314 left {_} {_} {_} {_} {_} {h} eq = ≡-cong ( λ k → k h ) eq |
715 | 315 open Relation.Binary.PropositionalEquality |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
316 FφF→F : { a b c d e : Obj Sets } { g : Hom Sets a c } { h : Hom Sets b d } |
715 | 317 { f : Hom Sets (c * d) e } |
318 { x : FObj F a } { y : FObj F b } | |
319 → FMap F f ( φ ( FMap F g x , FMap F h y ) ) ≡ FMap F ( f o map g h ) ( φ ( x , y ) ) | |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
320 FφF→F {a} {b} {c} {d} {e} {g} {h} {f} {x} {y} = sym ( begin |
715 | 321 FMap F ( f o map g h ) ( φ ( x , y ) ) |
322 ≡⟨ ≡-cong ( λ k → k ( φ ( x , y ))) ( IsFunctor.distr (isFunctor F) ) ⟩ | |
323 FMap F f (( FMap F ( map g h ) ) ( φ ( x , y ))) | |
324 ≡⟨ ≡-cong ( λ k → FMap F f k ) ( IsHaskellMonoidalFunctor.natφ mono ) ⟩ | |
325 FMap F f ( φ ( FMap F g x , FMap F h y ) ) | |
326 ∎ ) | |
327 where | |
328 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
716 | 329 u→F : {a : Obj Sets } {u : FObj F a} → u ≡ FMap F id u |
330 u→F {a} {u} = sym ( ≡-cong ( λ k → k u ) ( IsFunctor.identity ( isFunctor F ) ) ) | |
331 φunitr : {a : Obj Sets } {u : FObj F a} → φ ( unit , u) ≡ FMap F (Iso.≅← (IsMonoidal.mλ-iso isM)) u | |
332 φunitr {a} {u} = sym ( begin | |
333 FMap F (Iso.≅← (IsMonoidal.mλ-iso isM)) u | |
334 ≡⟨ ≡-cong ( λ k → FMap F (Iso.≅← (IsMonoidal.mλ-iso isM)) k ) (sym (IsHaskellMonoidalFunctor.idlφ mono)) ⟩ | |
335 FMap F (Iso.≅← (IsMonoidal.mλ-iso isM)) ( FMap F (Iso.≅→ (IsMonoidal.mλ-iso isM)) ( φ ( unit , u) ) ) | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
336 ≡⟨ left ( sym ( IsFunctor.distr ( isFunctor F ) )) ⟩ |
716 | 337 (FMap F ( (Iso.≅← (IsMonoidal.mλ-iso isM)) o (Iso.≅→ (IsMonoidal.mλ-iso isM)))) ( φ ( unit , u) ) |
338 ≡⟨ ≡-cong ( λ k → FMap F k ( φ ( unit , u) )) (Iso.iso→ ( (IsMonoidal.mλ-iso isM) )) ⟩ | |
339 FMap F id ( φ ( unit , u) ) | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
340 ≡⟨ left ( IsFunctor.identity ( isFunctor F ) ) ⟩ |
716 | 341 id ( φ ( unit , u) ) |
342 ≡⟨⟩ | |
343 φ ( unit , u) | |
344 ∎ ) | |
345 where | |
346 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
347 φunitl : {a : Obj Sets } {u : FObj F a} → φ ( u , unit ) ≡ FMap F (Iso.≅← (IsMonoidal.mρ-iso isM)) u | |
348 φunitl {a} {u} = sym ( begin | |
349 FMap F (Iso.≅← (IsMonoidal.mρ-iso isM)) u | |
350 ≡⟨ ≡-cong ( λ k → FMap F (Iso.≅← (IsMonoidal.mρ-iso isM)) k ) (sym (IsHaskellMonoidalFunctor.idrφ mono)) ⟩ | |
351 FMap F (Iso.≅← (IsMonoidal.mρ-iso isM)) ( FMap F (Iso.≅→ (IsMonoidal.mρ-iso isM)) ( φ ( u , unit ) ) ) | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
352 ≡⟨ left ( sym ( IsFunctor.distr ( isFunctor F ) )) ⟩ |
716 | 353 (FMap F ( (Iso.≅← (IsMonoidal.mρ-iso isM)) o (Iso.≅→ (IsMonoidal.mρ-iso isM)))) ( φ ( u , unit ) ) |
354 ≡⟨ ≡-cong ( λ k → FMap F k ( φ ( u , unit ) )) (Iso.iso→ ( (IsMonoidal.mρ-iso isM) )) ⟩ | |
355 FMap F id ( φ ( u , unit ) ) | |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
356 ≡⟨ left ( IsFunctor.identity ( isFunctor F ) ) ⟩ |
716 | 357 id ( φ ( u , unit ) ) |
358 ≡⟨⟩ | |
359 φ ( u , unit ) | |
360 ∎ ) | |
361 where | |
362 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
715 | 363 open IsMonoidal |
713 | 364 identity : { a : Obj Sets } { u : FObj F a } → pure ( id1 Sets a ) <*> u ≡ u |
365 identity {a} {u} = begin | |
714 | 366 pure id <*> u |
713 | 367 ≡⟨⟩ |
715 | 368 ( FMap F ( λ r → ( proj₁ r ) ( proj₂ r )) ) ( φ ( FMap F ( λ y → id ) unit , u ) ) |
716 | 369 ≡⟨ ≡-cong ( λ k → ( FMap F ( λ r → ( proj₁ r ) ( proj₂ r )) ) ( φ ( FMap F ( λ y → id ) unit , k ))) u→F ⟩ |
715 | 370 ( FMap F ( λ r → ( proj₁ r ) ( proj₂ r )) ) ( φ ( FMap F ( λ y → id ) unit , FMap F id u ) ) |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
371 ≡⟨ FφF→F ⟩ |
713 | 372 FMap F (λ x → proj₂ x ) (φ (unit , u ) ) |
373 ≡⟨⟩ | |
374 FMap F (Iso.≅→ (mλ-iso isM)) (φ (unit , u )) | |
715 | 375 ≡⟨ IsHaskellMonoidalFunctor.idlφ mono ⟩ |
713 | 376 u |
377 ∎ | |
378 where | |
379 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
380 composition : { a b c : Obj Sets } { u : FObj F ( b → c ) } { v : FObj F (a → b ) } { w : FObj F a } | |
381 → (( pure _・_ <*> u ) <*> v ) <*> w ≡ u <*> (v <*> w) | |
382 composition {a} {b} {c} {u} {v} {w} = begin | |
715 | 383 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ |
384 (FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f g x → f (g x)) unit , u)) , v)) , w)) | |
716 | 385 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f g x → f (g x)) unit , k)) , v)) , w)) ) u→F ⟩ |
715 | 386 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ |
716 | 387 (FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f g x → f (g x)) unit , FMap F id u )) , v)) , w)) |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
388 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ ( k , v)) , w)) ) FφF→F ⟩ |
715 | 389 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ |
716 | 390 (FMap F ( λ x → (λ r → proj₁ r (proj₂ r)) ((map (λ y f g x → f (g x)) id ) x)) (φ ( unit , u)) , v)) , w)) |
391 ≡⟨ ≡-cong ( λ k → ( FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ | |
392 (FMap F ( λ x → (λ r → proj₁ r (proj₂ r)) ((map (λ y f g x → f (g x)) id ) x)) k , v)) , w)) ) ) φunitr ⟩ | |
715 | 393 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ |
716 | 394 ( (FMap F ( λ x → (λ r → proj₁ r (proj₂ r)) ((map (λ y f g x → f (g x)) id ) x)) (FMap F (Iso.≅← (mλ-iso isM)) u) ) , v)) , w)) |
395 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ | |
396 (k u , v)) , w)) ) (sym ( IsFunctor.distr (isFunctor F ))) ⟩ | |
397 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ | |
398 ( FMap F (λ x → ((λ y f g x₁ → f (g x₁)) unit x) ) u , v)) , w)) | |
714 | 399 ≡⟨⟩ |
715 | 400 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ |
716 | 401 ( FMap F (λ x g h → x (g h) ) u , v)) , w)) |
402 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ ( FMap F (λ x g h → x (g h) ) u , k)) , w)) ) u→F ⟩ | |
403 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ x g h → x (g h)) u , FMap F id v)) , w)) | |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
404 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (k , w)) ) FφF→F ⟩ |
716 | 405 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F ((λ r → proj₁ r (proj₂ r)) o map (λ x g h → x (g h)) id) (φ (u , v)) , w)) |
715 | 406 ≡⟨⟩ |
716 | 407 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ x h → proj₁ x (proj₂ x h)) (φ (u , v)) , w)) |
408 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ x h → proj₁ x (proj₂ x h)) (φ (u , v)) , k)) ) u→F ⟩ | |
409 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ x h → proj₁ x (proj₂ x h)) (φ (u , v)) , FMap F id w)) | |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
410 ≡⟨ FφF→F ⟩ |
716 | 411 FMap F ((λ r → proj₁ r (proj₂ r)) o map (λ x h → proj₁ x (proj₂ x h)) id) (φ (φ (u , v) , w)) |
714 | 412 ≡⟨⟩ |
716 | 413 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (φ (φ (u , v) , w)) |
414 ≡⟨ ≡-cong ( λ k → FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (k (φ (φ (u , v) , w)) )) (sym (IsFunctor.identity (isFunctor F ))) ⟩ | |
415 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F id (φ (φ (u , v) , w)) ) | |
416 ≡⟨ ≡-cong ( λ k → FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F k (φ (φ (u , v) , w)) ) ) (sym (Iso.iso→ (mα-iso isM))) ⟩ | |
417 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F ( (Iso.≅← (mα-iso isM)) o (Iso.≅→ (mα-iso isM))) (φ (φ (u , v) , w)) ) | |
418 ≡⟨ ≡-cong ( λ k → FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (k (φ (φ (u , v) , w)))) ( IsFunctor.distr (isFunctor F )) ⟩ | |
419 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F (Iso.≅← (mα-iso isM)) ( FMap F (Iso.≅→ (mα-iso isM)) (φ (φ (u , v) , w)) )) | |
420 ≡⟨ ≡-cong ( λ k → FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F (Iso.≅← (mα-iso isM)) k) ) (sym ( IsHaskellMonoidalFunctor.assocφ mono ) ) ⟩ | |
421 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F (Iso.≅← (mα-iso isM)) (φ (u , φ (v , w)))) | |
715 | 422 ≡⟨⟩ |
716 | 423 FMap F (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) (FMap F (λ r → (proj₁ r , proj₁ (proj₂ r)) , proj₂ (proj₂ r)) (φ (u , φ (v , w)))) |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
424 ≡⟨ left (sym ( IsFunctor.distr (isFunctor F ))) ⟩ |
716 | 425 FMap F (λ y → (λ x → proj₁ (proj₁ x) (proj₂ (proj₁ x) (proj₂ x))) ((λ r → (proj₁ r , proj₁ (proj₂ r)) , proj₂ (proj₂ r)) y )) (φ (u , φ (v , w))) |
715 | 426 ≡⟨⟩ |
716 | 427 FMap F (λ y → proj₁ y (proj₁ (proj₂ y) (proj₂ (proj₂ y)))) (φ (u , φ (v , w))) |
715 | 428 ≡⟨⟩ |
429 FMap F ( λ x → (proj₁ x) ((λ r → proj₁ r (proj₂ r)) ( proj₂ x))) ( φ ( u , (φ (v , w)))) | |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
430 ≡⟨ sym FφF→F ⟩ |
715 | 431 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F id u , FMap F (λ r → proj₁ r (proj₂ r)) (φ (v , w)))) |
716 | 432 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (k , FMap F (λ r → proj₁ r (proj₂ r)) (φ (v , w)))) ) (sym u→F ) ⟩ |
715 | 433 FMap F (λ r → proj₁ r (proj₂ r)) (φ (u , FMap F (λ r → proj₁ r (proj₂ r)) (φ (v , w)))) |
713 | 434 ∎ |
435 where | |
436 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
437 homomorphism : { a b : Obj Sets } { f : Hom Sets a b } { x : a } → pure f <*> pure x ≡ pure (f x) | |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
438 homomorphism {a} {b} {f} {x} = begin |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
439 pure f <*> pure x |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
440 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
441 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y → f) unit , FMap F (λ y → x) unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
442 ≡⟨ FφF→F ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
443 FMap F ((λ r → proj₁ r (proj₂ r)) o map (λ y → f) (λ y → x)) (φ (unit , unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
444 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
445 FMap F (λ y → f x) (φ (unit , unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
446 ≡⟨ ≡-cong ( λ k → FMap F (λ y → f x) k ) φunitl ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
447 FMap F (λ y → f x) (FMap F (Iso.≅← (mρ-iso isM)) unit) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
448 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
449 FMap F (λ y → f x) (FMap F (λ y → (y , OneObj)) unit) |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
450 ≡⟨ left ( sym ( IsFunctor.distr (isFunctor F ))) ⟩ |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
451 FMap F (λ y → f x) unit |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
452 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
453 pure (f x) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
454 ∎ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
455 where |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
456 open Relation.Binary.PropositionalEquality.≡-Reasoning |
713 | 457 interchange : { a b : Obj Sets } { u : FObj F ( a → b ) } { x : a } → u <*> pure x ≡ pure (λ f → f x) <*> u |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
458 interchange {a} {b} {u} {x} = begin |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
459 u <*> pure x |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
460 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
461 FMap F (λ r → proj₁ r (proj₂ r)) (φ (u , FMap F (λ y → x) unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
462 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (k , FMap F (λ y → x) unit)) ) u→F ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
463 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F id u , FMap F (λ y → x) unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
464 ≡⟨ FφF→F ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
465 FMap F ((λ r → proj₁ r (proj₂ r)) o map id (λ y → x)) (φ (u , unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
466 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
467 FMap F (λ r → proj₁ r x) (φ (u , unit)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
468 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r x) k ) φunitl ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
469 FMap F (λ r → proj₁ r x) (( FMap F (Iso.≅← (mρ-iso isM))) u ) |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
470 ≡⟨ left ( sym ( IsFunctor.distr (isFunctor F )) ) ⟩ |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
471 FMap F (( λ r → proj₁ r x) o ((Iso.≅← (mρ-iso isM) ))) u |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
472 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
473 FMap F (( λ r → proj₂ r x) o ((Iso.≅← (mλ-iso isM) ))) u |
721
a8b595fb4905
use FMap F f x ≡ pure f <*> x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
720
diff
changeset
|
474 ≡⟨ left ( IsFunctor.distr (isFunctor F )) ⟩ |
717
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
475 FMap F (λ r → proj₂ r x) (FMap F (Iso.≅← (IsMonoidal.mλ-iso isM)) u) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
476 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₂ r x) k ) (sym φunitr ) ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
477 FMap F (λ r → proj₂ r x) (φ (unit , u)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
478 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
479 FMap F ((λ r → proj₁ r (proj₂ r)) o map (λ y f → f x) id) (φ (unit , u)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
480 ≡⟨ sym FφF→F ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
481 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f → f x) unit , FMap F id u)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
482 ≡⟨ ≡-cong ( λ k → FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f → f x) unit , k)) ) (sym u→F) ⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
483 FMap F (λ r → proj₁ r (proj₂ r)) (φ (FMap F (λ y f → f x) unit , u)) |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
484 ≡⟨⟩ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
485 pure (λ f → f x) <*> u |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
486 ∎ |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
487 where |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
488 open Relation.Binary.PropositionalEquality.≡-Reasoning |
a41b2b9b0407
Haskell Monoidal Funtor to Applicative done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
716
diff
changeset
|
489 |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
490 ---- |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
491 -- |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
492 -- Applicative laws imples Monoidal laws |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
493 -- |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
494 |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
495 Applicative→HaskellMonoidal : {c₁ : Level} ( F : Functor (Sets {c₁}) (Sets {c₁}) ) |
766 | 496 ( App : Applicative F ) |
497 → HaskellMonoidalFunctor F | |
498 Applicative→HaskellMonoidal {l} F App = record { | |
499 unit = unit ; | |
500 φ = φ ; | |
501 isHaskellMonoidalFunctor = record { | |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
502 natφ = natφ |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
503 ; assocφ = assocφ |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
504 ; idrφ = idrφ |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
505 ; idlφ = idlφ |
766 | 506 } |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
507 } where |
766 | 508 pure = Applicative.pure App |
509 <*> = Applicative.<*> App | |
510 app = Applicative.isApplicative App | |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
511 unit : FObj F One |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
512 unit = pure OneObj |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
513 φ : {a b : Obj Sets} → Hom Sets ((FObj F a) * (FObj F b )) ( FObj F ( a * b ) ) |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
514 φ = λ x → <*> (FMap F (λ j k → (j , k)) ( proj₁ x)) ( proj₂ x) |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
515 isM : IsMonoidal (Sets {l}) One SetsTensorProduct |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
516 isM = Monoidal.isMonoidal MonoidalSets |
766 | 517 MF : MonoidalFunctor {_} {l} {_} {Sets} {Sets} MonoidalSets MonoidalSets |
518 MF = Applicative→Monoidal F App app | |
519 isMF = MonoidalFunctor.isMonodailFunctor MF | |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
520 natφ : { a b c d : Obj Sets } { x : FObj F a} { y : FObj F b} { f : a → c } { g : b → d } |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
521 → FMap F (map f g) (φ (x , y)) ≡ φ (FMap F f x , FMap F g y) |
766 | 522 natφ {a} {b} {c} {d} {x} {y} {f} {g} = begin |
523 FMap F (map f g) (φ (x , y)) | |
524 ≡⟨⟩ | |
525 FMap F (λ xy → f (proj₁ xy) , g (proj₂ xy)) (<*> (FMap F (λ j k → j , k) x) y) | |
526 ≡⟨ ≡-cong ( λ h → h (x , y)) ( IsNTrans.commute ( NTrans.isNTrans ( IsMonoidalFunctor.φab isMF ))) ⟩ | |
527 <*> (FMap F (λ j k → j , k) (FMap F f x)) (FMap F g y) | |
528 ≡⟨⟩ | |
529 φ (FMap F f x , FMap F g y) | |
530 ∎ | |
531 where | |
532 open Relation.Binary.PropositionalEquality.≡-Reasoning | |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
533 assocφ : { x y z : Obj Sets } { a : FObj F x } { b : FObj F y }{ c : FObj F z } |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
534 → φ (a , φ (b , c)) ≡ FMap F (Iso.≅→ (IsMonoidal.mα-iso isM)) (φ (φ (a , b) , c)) |
766 | 535 assocφ {x} {y} {z} {a} {b} {c} = ≡-cong ( λ h → h ((a , b) , c ) ) ( IsMonoidalFunctor.associativity isMF ) |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
536 idrφ : {a : Obj Sets } { x : FObj F a } → FMap F (Iso.≅→ (IsMonoidal.mρ-iso isM)) (φ (x , unit)) ≡ x |
766 | 537 idrφ {a} {x} = ≡-cong ( λ h → h (x , OneObj ) ) ( IsMonoidalFunctor.unitarity-idr isMF {a} {One} ) |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
538 idlφ : {a : Obj Sets } { x : FObj F a } → FMap F (Iso.≅→ (IsMonoidal.mλ-iso isM)) (φ (unit , x)) ≡ x |
766 | 539 idlφ {a} {x} = ≡-cong ( λ h → h (OneObj , x ) ) ( IsMonoidalFunctor.unitarity-idl isMF {One} {a} ) |
765
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
540 |
171f5386e87e
Applicative→HaskellMonoidal begin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
732
diff
changeset
|
541 |