|
1 (* Title: HOL/Datatype_Examples/Misc_Codatatype.thy |
|
2 Author: Dmitriy Traytel, TU Muenchen |
|
3 Author: Andrei Popescu, TU Muenchen |
|
4 Author: Jasmin Blanchette, TU Muenchen |
|
5 Copyright 2012, 2013 |
|
6 |
|
7 Miscellaneous codatatype definitions. |
|
8 *) |
|
9 |
|
10 header {* Miscellaneous Codatatype Definitions *} |
|
11 |
|
12 theory Misc_Codatatype |
|
13 imports "~~/src/HOL/Library/FSet" |
|
14 begin |
|
15 |
|
16 codatatype simple = X1 | X2 | X3 | X4 |
|
17 |
|
18 codatatype simple' = X1' unit | X2' unit | X3' unit | X4' unit |
|
19 |
|
20 codatatype simple'' = X1'' nat int | X2'' |
|
21 |
|
22 codatatype 'a stream = Stream (shd: 'a) (stl: "'a stream") |
|
23 |
|
24 codatatype 'a mylist = MyNil | MyCons (myhd: 'a) (mytl: "'a mylist") |
|
25 |
|
26 codatatype ('b, 'c :: ord, 'd, 'e) some_passive = |
|
27 SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e |
|
28 |
|
29 codatatype lambda = |
|
30 Var string | |
|
31 App lambda lambda | |
|
32 Abs string lambda | |
|
33 Let "(string \<times> lambda) fset" lambda |
|
34 |
|
35 codatatype 'a par_lambda = |
|
36 PVar 'a | |
|
37 PApp "'a par_lambda" "'a par_lambda" | |
|
38 PAbs 'a "'a par_lambda" | |
|
39 PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda" |
|
40 |
|
41 (* |
|
42 ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2 |
|
43 ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2 |
|
44 *) |
|
45 |
|
46 codatatype 'a p = P "'a + 'a p" |
|
47 |
|
48 codatatype 'a J1 = J11 'a "'a J1" | J12 'a "'a J2" |
|
49 and 'a J2 = J21 | J22 "'a J1" "'a J2" |
|
50 |
|
51 codatatype 'a tree = TEmpty | TNode 'a "'a forest" |
|
52 and 'a forest = FNil | FCons "'a tree" "'a forest" |
|
53 |
|
54 codatatype 'a tree' = TEmpty' | TNode' "'a branch" "'a branch" |
|
55 and 'a branch = Branch 'a "'a tree'" |
|
56 |
|
57 codatatype 'a bin_rose_tree = BRTree 'a "'a bin_rose_tree mylist" "'a bin_rose_tree mylist" |
|
58 |
|
59 codatatype ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp" |
|
60 and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm" |
|
61 and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp" |
|
62 |
|
63 codatatype ('a, 'b, 'c) some_killing = |
|
64 SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here" |
|
65 and ('a, 'b, 'c) in_here = |
|
66 IH1 'b 'a | IH2 'c |
|
67 |
|
68 codatatype ('a, 'b, 'c) some_killing' = |
|
69 SK' "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing' + ('a, 'b, 'c) in_here'" |
|
70 and ('a, 'b, 'c) in_here' = |
|
71 IH1' 'b | IH2' 'c |
|
72 |
|
73 codatatype ('a, 'b, 'c) some_killing'' = |
|
74 SK'' "'a \<Rightarrow> ('a, 'b, 'c) in_here''" |
|
75 and ('a, 'b, 'c) in_here'' = |
|
76 IH1'' 'b 'a | IH2'' 'c |
|
77 |
|
78 codatatype ('b, 'c) less_killing = LK "'b \<Rightarrow> 'c" |
|
79 |
|
80 codatatype 'b poly_unit = U "'b \<Rightarrow> 'b poly_unit" |
|
81 codatatype 'b cps = CPS1 'b | CPS2 "'b \<Rightarrow> 'b cps" |
|
82 |
|
83 codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs = |
|
84 FR "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> |
|
85 ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9) fun_rhs" |
|
86 |
|
87 codatatype ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17, |
|
88 'b18, 'b19, 'b20) fun_rhs' = |
|
89 FR' "'b1 \<Rightarrow> 'b2 \<Rightarrow> 'b3 \<Rightarrow> 'b4 \<Rightarrow> 'b5 \<Rightarrow> 'b6 \<Rightarrow> 'b7 \<Rightarrow> 'b8 \<Rightarrow> 'b9 \<Rightarrow> 'b10 \<Rightarrow> 'b11 \<Rightarrow> 'b12 \<Rightarrow> 'b13 \<Rightarrow> 'b14 \<Rightarrow> |
|
90 'b15 \<Rightarrow> 'b16 \<Rightarrow> 'b17 \<Rightarrow> 'b18 \<Rightarrow> 'b19 \<Rightarrow> 'b20 \<Rightarrow> |
|
91 ('b1, 'b2, 'b3, 'b4, 'b5, 'b6, 'b7, 'b8, 'b9, 'b10, 'b11, 'b12, 'b13, 'b14, 'b15, 'b16, 'b17, |
|
92 'b18, 'b19, 'b20) fun_rhs'" |
|
93 |
|
94 codatatype ('a, 'b, 'c) wit3_F1 = W1 'a "('a, 'b, 'c) wit3_F1" "('a, 'b, 'c) wit3_F2" |
|
95 and ('a, 'b, 'c) wit3_F2 = W2 'b "('a, 'b, 'c) wit3_F2" |
|
96 and ('a, 'b, 'c) wit3_F3 = W31 'a 'b "('a, 'b, 'c) wit3_F1" | W32 'c 'a 'b "('a, 'b, 'c) wit3_F1" |
|
97 |
|
98 codatatype ('c, 'e, 'g) coind_wit1 = |
|
99 CW1 'c "('c, 'e, 'g) coind_wit1" "('c, 'e, 'g) ind_wit" "('c, 'e, 'g) coind_wit2" |
|
100 and ('c, 'e, 'g) coind_wit2 = |
|
101 CW21 "('c, 'e, 'g) coind_wit2" 'e | CW22 'c 'g |
|
102 and ('c, 'e, 'g) ind_wit = |
|
103 IW1 | IW2 'c |
|
104 |
|
105 codatatype ('b, 'a) bar = BAR "'a \<Rightarrow> 'b" |
|
106 codatatype ('a, 'b, 'c, 'd) foo = FOO "'d + 'b \<Rightarrow> 'c + 'a" |
|
107 |
|
108 codatatype 'a dead_foo = A |
|
109 codatatype ('a, 'b) use_dead_foo = Y "'a" "'b dead_foo" |
|
110 |
|
111 (* SLOW, MEMORY-HUNGRY |
|
112 codatatype ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list" |
|
113 and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list" |
|
114 and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5" |
|
115 and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list" |
|
116 and ('a, 'c) D5 = A5 "('a, 'c) D6" |
|
117 and ('a, 'c) D6 = A6 "('a, 'c) D7" |
|
118 and ('a, 'c) D7 = A7 "('a, 'c) D8" |
|
119 and ('a, 'c) D8 = A8 "('a, 'c) D1 list" |
|
120 *) |
|
121 |
|
122 end |