Mercurial > hg > Members > atton > agda-proofs
annotate cbc/variable-tuple.agda @ 25:da78bb99d654
Embed function body to codesegment
author | atton <atton@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 23 Dec 2016 02:36:46 +0000 |
parents | 0fcb7b35ba81 |
children | d503a73186ce |
rev | line source |
---|---|
17 | 1 module variable-tuple where |
2 | |
3 open import Data.Nat hiding (_<_ ; _>_) | |
4 open import Data.String | |
5 open import Data.List | |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
6 open import Data.Unit |
19
853318ff55f9
Trying define output data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
7 open import Data.Product |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
8 open import Function using (_∘_ ; id) |
17 | 9 open import Relation.Binary.PropositionalEquality |
24
0fcb7b35ba81
Add data version CodeSegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
10 open import Level hiding (zero) |
17 | 11 |
12 data Format : Set₁ where | |
13 FEnd : Format | |
14 FSet : Set -> Format -> Format | |
15 | |
16 <> : Format | |
17 <> = FEnd | |
18 | |
19 infix 51 _> | |
20 _> : (Format -> Format) -> Format | |
21 _> f = f FEnd | |
22 | |
23 infixl 52 _||_ | |
24 _||_ : (Format -> Format) -> Set -> (Format -> Format) | |
25 _||_ f1 s = f1 ∘ (FSet s) | |
26 | |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
27 infix 53 <_ |
17 | 28 <_ : Set -> Format -> Format |
29 <_ s = FSet s | |
30 | |
31 | |
32 unit : Format | |
33 unit = <> | |
34 | |
35 single : Format | |
36 single = < ℕ > | |
37 | |
38 double : Format | |
39 double = < String || ℕ > | |
40 | |
41 triple : Format | |
42 triple = < String || ℕ || (List ℕ) > | |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
43 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
44 data CodeSegment (I O : Set) : Set₁ where |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
45 cs : (I -> O) -> CodeSegment I O |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
46 |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
47 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
48 twiceWithName : (String × ℕ ) -> (String × ℕ ) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
49 twiceWithName (s , n) = s , twice n |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
50 where |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
51 twice : ℕ -> ℕ |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
52 twice zero = zero |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
53 twice (ℕ.suc n₁) = (ℕ.suc (ℕ.suc (twice n₁))) |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
54 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
55 csDouble : CodeSegment (String × ℕ) (String × ℕ) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
56 csDouble = cs twiceWithName |
19
853318ff55f9
Trying define output data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
57 |
22
84e3fbc662db
Define cs compose operator
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
58 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
59 ods : {I O : Set} -> CodeSegment I O -> Set |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
60 ods {i} {o} c = o |
19
853318ff55f9
Trying define output data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
61 |
853318ff55f9
Trying define output data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
62 ods-double : ods csDouble |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
63 ods-double = "hoge" , zero |
19
853318ff55f9
Trying define output data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
64 |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
65 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
66 ids : {I O : Set} -> CodeSegment I O -> Set |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
67 ids {i} {o} c = i |
22
84e3fbc662db
Define cs compose operator
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
68 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
69 ids-double : ids csDouble |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
70 ids-double = "fuga" , 3 |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
71 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
72 --ids-double : {A : Set} {a : A} -> ids csDouble |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
73 --ids-double {_} {a} = \(s : String) -> \(n : ℕ) -> a |
18
782a11f3eea4
Trying define input data segment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
74 |
20
4dd4400b48aa
Define code segment execution
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
75 |
24
0fcb7b35ba81
Add data version CodeSegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
76 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
77 executeCS : {A B : Set} -> CodeSegment A B -> (A -> B) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
78 executeCS (cs b) = b |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
79 |
20
4dd4400b48aa
Define code segment execution
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
80 |
22
84e3fbc662db
Define cs compose operator
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
81 |
24
0fcb7b35ba81
Add data version CodeSegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
82 infixr 30 _◎_ |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
83 _◎_ : {A B C : Set} -> CodeSegment A B -> CodeSegment B C -> CodeSegment A C |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
84 (cs b1) ◎ (cs b2) = cs (b2 ∘ b1) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
85 |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
86 |
22
84e3fbc662db
Define cs compose operator
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
87 |
84e3fbc662db
Define cs compose operator
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
88 |
25
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
89 ◎-double : CodeSegment (String × ℕ) (String × ℕ ) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
90 --◎-double = csDouble ◎ csDouble ◎ csDouble -- ok |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
91 ◎-double = csDouble ◎ (cs (\s -> tt)) ◎ (cs (\t -> ("yo" , 100))) -- ok |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
92 --◎-double = csDouble ◎ (cs (\s -> tt)) ◎ csDouble -- ng (valid type check) |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
93 |
da78bb99d654
Embed function body to codesegment
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
24
diff
changeset
|
94 |