Mercurial > hg > Members > atton > delta_monad
annotate agda/deltaM.agda @ 121:673e1ca0d1a9
Refactor monad definition
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Feb 2015 12:11:24 +0900 |
parents | 0f9ecd118a03 |
children | 5902b2a24abf |
rev | line source |
---|---|
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 open import Level |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
3 open import basic |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 open import delta |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 open import delta.functor |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 open import nat |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 open import laws |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 module deltaM where |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 -- DeltaM definitions |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
13 data DeltaM {l : Level} {T : Set l -> Set l} {F : Functor T} |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
14 (M : Monad T F) (A : Set l) : (Nat -> Set l) where |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
15 deltaM : {n : Nat} -> Delta (T A) (S n) -> DeltaM M A (S n) |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 -- DeltaM utils |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 |
118
53cb21845dea
Prove association-law for DeltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
20 unDeltaM : {l : Level} {A : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
21 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
22 (DeltaM M A (S n)) -> Delta (T A) (S n) |
118
53cb21845dea
Prove association-law for DeltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
23 unDeltaM (deltaM d) = d |
53cb21845dea
Prove association-law for DeltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
24 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
25 |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
26 |
109
5bd5f4a7ce8d
Redefine DeltaM that length fixed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
27 headDeltaM : {l : Level} {A : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
28 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
29 DeltaM M A (S n) -> T A |
100
d8cd880f1d78
Redefine some functions DeltaM in agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
95
diff
changeset
|
30 headDeltaM (deltaM d) = headDelta d |
d8cd880f1d78
Redefine some functions DeltaM in agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
95
diff
changeset
|
31 |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
33 |
109
5bd5f4a7ce8d
Redefine DeltaM that length fixed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
34 tailDeltaM : {l : Level} {A : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
35 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
36 DeltaM M A (S (S n)) -> DeltaM M A (S n) |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
37 tailDeltaM {_} {n} (deltaM d) = deltaM (tailDelta d) |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 |
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
40 |
109
5bd5f4a7ce8d
Redefine DeltaM that length fixed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
41 appendDeltaM : {l : Level} {A : Set l} {n m : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
42 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
43 DeltaM M A (S n) -> DeltaM M A (S m) -> DeltaM M A ((S n) + (S m)) |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
44 appendDeltaM (deltaM d) (deltaM dd) = deltaM (deltaAppend d dd) |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
45 |
89
5411ce26d525
Defining DeltaM in Agda...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
115
e6bcc7467335
Temporary commit : Proving association-law ...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
47 dmap : {l : Level} {A B : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
48 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
49 (T A -> B) -> DeltaM M A (S n) -> Delta B (S n) |
115
e6bcc7467335
Temporary commit : Proving association-law ...
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
50 dmap f (deltaM d) = delta-fmap f d |
90
55d11ce7e223
Unify levels on data type. only use suc to proofs
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
51 |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
52 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
53 |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
54 |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
55 -- functor definitions |
90
55d11ce7e223
Unify levels on data type. only use suc to proofs
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
89
diff
changeset
|
56 open Functor |
109
5bd5f4a7ce8d
Redefine DeltaM that length fixed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
57 deltaM-fmap : {l : Level} {A B : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
58 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
59 (A -> B) -> DeltaM M A (S n) -> DeltaM M B (S n) |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
60 deltaM-fmap {l} {A} {B} {n} {M} {functorM} f (deltaM d) = deltaM (fmap delta-is-functor (fmap functorM f) d) |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
61 |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
62 |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
63 |
94
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
64 |
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
65 -- monad definitions |
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
66 open Monad |
bcd4fe52a504
Rewrite monad definitions for delta/deltaM
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
90
diff
changeset
|
67 |
109
5bd5f4a7ce8d
Redefine DeltaM that length fixed
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
68 deltaM-eta : {l : Level} {A : Set l} {n : Nat} |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
69 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
70 A -> (DeltaM M A (S n)) |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
71 deltaM-eta {n = n} {M = M} x = deltaM (delta-eta {n = n} (eta M x)) |
100
d8cd880f1d78
Redefine some functions DeltaM in agda
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
95
diff
changeset
|
72 |
104
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
73 |
ebd0d6e2772c
Trying redenition Delta with length constraints
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
74 |
120
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
75 deltaM-mu : {l : Level} {A : Set l} {n : Nat} |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
76 {T : Set l -> Set l} {F : Functor T} {M : Monad T F} -> |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
77 DeltaM M (DeltaM M A (S n)) (S n) -> DeltaM M A (S n) |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
78 deltaM-mu {n = O} {F = F} {M = M} d = deltaM (mono (mu M (fmap F headDeltaM (headDeltaM d)))) |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
79 deltaM-mu {n = S n} {F = F} {M = M} d = deltaM (delta (mu M (fmap F headDeltaM (headDeltaM d))) |
0f9ecd118a03
Refactor DeltaM definition
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
118
diff
changeset
|
80 (unDeltaM (deltaM-mu (deltaM-fmap tailDeltaM (tailDeltaM d))))) |