Mercurial > hg > Members > atton > delta_monad
annotate agda/delta.agda @ 43:90b171e3a73e
Rename to Delta from Similar
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 01 Nov 2014 15:19:04 +0900 |
parents | agda/similar.agda@1df4f9d88025 |
children | 9bb7c9bee94f |
rev | line source |
---|---|
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 open import list |
28
6e6d646d7722
Split basic functions to file
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
2 open import basic |
29
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
3 |
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
4 open import Level |
27
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
5 open import Relation.Binary.PropositionalEquality |
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
6 open ≡-Reasoning |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
8 module delta where |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
10 data Delta {l : Level} (A : Set l) : (Set (suc l)) where |
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
11 similar : List String -> A -> List String -> A -> Delta A |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
13 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
14 -- Functor |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
15 fmap : {l ll : Level} {A : Set l} {B : Set ll} -> (A -> B) -> (Delta A) -> (Delta B) |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 fmap f (similar xs x ys y) = similar xs (f x) ys (f y) |
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
18 |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
19 -- Monad (Category) |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
20 mu : {l : Level} {A : Set l} -> Delta (Delta A) -> Delta A |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 mu (similar lx (similar llx x _ _) ly (similar _ _ lly y)) = similar (lx ++ llx) x (ly ++ lly) y |
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
23 eta : {l : Level} {A : Set l} -> A -> Delta A |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
24 eta x = similar [] x [] x |
27
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
25 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
26 returnS : {l : Level} {A : Set l} -> A -> Delta A |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 returnS x = similar [[ (show x) ]] x [[ (show x) ]] x |
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
29 returnSS : {l : Level} {A : Set l} -> A -> A -> Delta A |
26
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 returnSS x y = similar [[ (show x) ]] x [[ (show y) ]] y |
5ba82f107a95
Define Similar in Agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 |
33 | 32 |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
33 -- Monad (Haskell) |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
34 return : {l : Level} {A : Set l} -> A -> Delta A |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
35 return = eta |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
36 |
41
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
37 |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
38 _>>=_ : {l ll : Level} {A : Set l} {B : Set ll} -> |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
39 (x : Delta A) -> (f : A -> (Delta B)) -> (Delta B) |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
40 x >>= f = mu (fmap f x) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
41 |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
42 |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
43 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
44 -- proofs |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
45 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
46 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
47 -- Functor-laws |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
48 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
49 -- Functor-law-1 : T(id) = id' |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
50 functor-law-1 : {l : Level} {A : Set l} -> (s : Delta A) -> (fmap id) s ≡ id s |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
51 functor-law-1 (similar lx x ly y) = refl |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
52 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
53 -- Functor-law-2 : T(f . g) = T(f) . T(g) |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
54 functor-law-2 : {l ll lll : Level} {A : Set l} {B : Set ll} {C : Set lll} -> |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
55 (f : B -> C) -> (g : A -> B) -> (s : Delta A) -> |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
56 (fmap (f ∙ g)) s ≡ ((fmap f) ∙ (fmap g)) s |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
57 functor-law-2 f g (similar lx x ly y) = refl |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
58 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
59 |
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
60 |
39 | 61 -- Monad-laws (Category) |
38
6ce83b2c9e59
Proof Functor-laws
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
36
diff
changeset
|
62 |
39 | 63 -- monad-law-1 : join . fmap join = join . join |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
64 monad-law-1 : {l : Level} {A : Set l} -> (s : Delta (Delta (Delta A))) -> ((mu ∙ (fmap mu)) s) ≡ ((mu ∙ mu) s) |
41
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
65 monad-law-1 (similar lx (similar llx (similar lllx x _ _) _ (similar _ _ _ _)) |
32
71906644d206
Expand monad-law 1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
66 ly (similar _ (similar _ _ _ _) lly (similar _ _ llly y))) = begin |
71906644d206
Expand monad-law 1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
67 similar (lx ++ (llx ++ lllx)) x (ly ++ (lly ++ llly)) y |
33 | 68 ≡⟨ cong (\left-list -> similar left-list x (ly ++ (lly ++ llly)) y) (list-associative lx llx lllx) ⟩ |
69 similar (lx ++ llx ++ lllx) x (ly ++ (lly ++ llly)) y | |
70 ≡⟨ cong (\right-list -> similar (lx ++ llx ++ lllx) x right-list y ) (list-associative ly lly llly) ⟩ | |
32
71906644d206
Expand monad-law 1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
71 similar (lx ++ llx ++ lllx) x (ly ++ lly ++ llly) y |
29
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
72 ∎ |
e0ba1bf564dd
Apply level to some functions
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
28
diff
changeset
|
73 |
34
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
74 |
39 | 75 -- monad-law-2 : join . fmap return = join . return = id |
76 -- monad-law-2-1 join . fmap return = join . return | |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
77 monad-law-2-1 : {l : Level} {A : Set l} -> (s : Delta A) -> |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
78 (mu ∙ fmap eta) s ≡ (mu ∙ eta) s |
34
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
79 monad-law-2-1 (similar lx x ly y) = begin |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
80 similar (lx ++ []) x (ly ++ []) y |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
81 ≡⟨ cong (\left-list -> similar left-list x (ly ++ []) y) (empty-append lx)⟩ |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
82 similar lx x (ly ++ []) y |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
83 ≡⟨ cong (\right-list -> similar lx x right-list y) (empty-append ly) ⟩ |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
84 similar lx x ly y |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
85 ∎ |
b7c4e6276bcf
Proof Monad-law-2-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
86 |
39 | 87 -- monad-law-2-2 : join . return = id |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
88 monad-law-2-2 : {l : Level} {A : Set l } -> (s : Delta A) -> (mu ∙ eta) s ≡ id s |
35
c5cdbedc68ad
Proof Monad-law-2-2
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
89 monad-law-2-2 (similar lx x ly y) = refl |
c5cdbedc68ad
Proof Monad-law-2-2
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
34
diff
changeset
|
90 |
39 | 91 -- monad-law-3 : return . f = fmap f . return |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
92 monad-law-3 : {l : Level} {A B : Set l} (f : A -> B) (x : A) -> (eta ∙ f) x ≡ (fmap f ∙ eta) x |
36 | 93 monad-law-3 f x = refl |
27
742e62fc63e4
Define Monad-law 1-4
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
26
diff
changeset
|
94 |
39 | 95 -- monad-law-4 : join . fmap (fmap f) = fmap f . join |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
96 monad-law-4 : {l ll : Level} {A : Set l} {B : Set ll} (f : A -> B) (s : Delta (Delta A)) -> |
36 | 97 (mu ∙ fmap (fmap f)) s ≡ (fmap f ∙ mu) s |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
98 monad-law-4 f (similar lx (similar llx x _ _) ly (similar _ _ lly y)) = refl |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
99 |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
100 |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
101 -- Monad-laws (Haskell) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
102 -- monad-law-h-1 : return a >>= k = k a |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
103 monad-law-h-1 : {l ll : Level} {A : Set l} {B : Set ll} -> |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
104 (a : A) -> (k : A -> (Delta B)) -> |
40
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
105 (return a >>= k) ≡ (k a) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
106 monad-law-h-1 a k = begin |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
107 return a >>= k |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
108 ≡⟨ refl ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
109 mu (fmap k (return a)) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
110 ≡⟨ refl ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
111 mu (return (k a)) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
112 ≡⟨ refl ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
113 (mu ∙ return) (k a) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
114 ≡⟨ refl ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
115 (mu ∙ eta) (k a) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
116 ≡⟨ (monad-law-2-2 (k a)) ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
117 id (k a) |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
118 ≡⟨ refl ⟩ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
119 k a |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
120 ∎ |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
121 |
a7cd7740f33e
Add Haskell style Monad-laws and Proof Monad-laws-h-1
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
39
diff
changeset
|
122 -- monad-law-h-2 : m >>= return = m |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
123 monad-law-h-2 : {l : Level}{A : Set l} -> (m : Delta A) -> (m >>= return) ≡ m |
41
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
124 monad-law-h-2 (similar lx x ly y) = monad-law-2-1 (similar lx x ly y) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
125 |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
126 -- monad-law-h-3 : m >>= (\x -> k x >>= h) = (m >>= k) >>= h |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
127 monad-law-h-3 : {l ll lll : Level} {A : Set l} {B : Set ll} {C : Set lll} -> |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
128 (m : Delta A) -> (k : A -> (Delta B)) -> (h : B -> (Delta C)) -> |
41
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
129 (m >>= (\x -> k x >>= h)) ≡ ((m >>= k) >>= h) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
130 monad-law-h-3 (similar lx x ly y) k h = begin |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
131 ((similar lx x ly y) >>= (\x -> (k x) >>= h)) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
132 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
133 mu (fmap (\x -> k x >>= h) (similar lx x ly y)) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
134 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
135 (mu ∙ fmap (\x -> k x >>= h)) (similar lx x ly y) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
136 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
137 (mu ∙ fmap (\x -> mu (fmap h (k x)))) (similar lx x ly y) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
138 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
139 (mu ∙ fmap (mu ∙ (\x -> fmap h (k x)))) (similar lx x ly y) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
140 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
141 (mu ∙ (fmap mu ∙ (fmap (\x -> fmap h (k x))))) (similar lx x ly y) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
142 ≡⟨ refl ⟩ |
42
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
143 (mu ∙ (fmap mu)) ((fmap (\x -> fmap h (k x))) (similar lx x ly y)) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
144 ≡⟨ monad-law-1 (((fmap (\x -> fmap h (k x))) (similar lx x ly y))) ⟩ |
43
90b171e3a73e
Rename to Delta from Similar
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
42
diff
changeset
|
145 (mu ∙ mu) ((fmap (\x -> fmap h (k x))) (similar lx x ly y)) |
42
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
146 ≡⟨ refl ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
147 (mu ∙ (mu ∙ (fmap (\x -> fmap h (k x))))) (similar lx x ly y) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
148 ≡⟨ refl ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
149 (mu ∙ (mu ∙ (fmap ((fmap h) ∙ k)))) (similar lx x ly y) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
150 ≡⟨ refl ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
151 (mu ∙ (mu ∙ ((fmap (fmap h)) ∙ (fmap k)))) (similar lx x ly y) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
152 ≡⟨ refl ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
153 (mu ∙ (mu ∙ (fmap (fmap h)))) (fmap k (similar lx x ly y)) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
154 ≡⟨ refl ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
155 mu ((mu ∙ (fmap (fmap h))) (fmap k (similar lx x ly y))) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
156 ≡⟨ cong (\fx -> mu fx) (monad-law-4 h (fmap k (similar lx x ly y))) ⟩ |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
157 mu (fmap h (mu (similar lx (k x) ly (k y)))) |
1df4f9d88025
Proof Monad-law-3 (haskell)
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
41
diff
changeset
|
158 ≡⟨ refl ⟩ |
41
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
159 (mu ∙ fmap h) (mu (fmap k (similar lx x ly y))) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
160 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
161 mu (fmap h (mu (fmap k (similar lx x ly y)))) |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
162 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
163 (mu (fmap k (similar lx x ly y))) >>= h |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
164 ≡⟨ refl ⟩ |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
165 ((similar lx x ly y) >>= k) >>= h |
23474bf242c6
Proof monad-law-h-2, trying monad-law-h-3
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
40
diff
changeset
|
166 ∎ |