author | Christian Urban <urbanc@in.tum.de> |
Sun, 07 Mar 2010 21:30:57 +0100 | |
changeset 1355 | 7b0c6d07a24e |
parent 1346 | 998b1bde64e7 |
child 1360 | c54cb3f7ac70 |
child 1363 | f00761b5957e |
permissions | -rw-r--r-- |
1261
853abc14c5c6
added IsaMakefile...but so far included only a test for the parser
Christian Urban <urbanc@in.tum.de>
parents:
1258
diff
changeset
|
1 |
theory Parser |
1309 | 2 |
imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "Perm" "Fv" "Rsp" |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
atom_decl name |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
7 |
section{* Interface for nominal_datatype *} |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
8 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
9 |
text {* |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
10 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
11 |
Nominal-Datatype-part: |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
12 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
13 |
|
1266 | 14 |
1nd Arg: (string list * binding * mixfix * (binding * typ list * mixfix) list) list |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
15 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
16 |
type(s) to be defined constructors list |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
17 |
(ty args, name, syn) (name, typs, syn) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
18 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
19 |
Binder-Function-part: |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
20 |
|
1266 | 21 |
2rd Arg: (binding * typ option * mixfix) list |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
22 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
23 |
binding function(s) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
24 |
to be defined |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
25 |
(name, type, syn) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
26 |
|
1266 | 27 |
3th Arg: term list |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
28 |
^^^^^^^^^ |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
29 |
the equations of the binding functions |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
30 |
(Trueprop equations) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
|
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
33 |
ML {* |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
34 |
|
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
35 |
*} |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
36 |
|
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
37 |
text {*****************************************************} |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
38 |
ML {* |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
39 |
(* nominal datatype parser *) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
40 |
local |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
41 |
structure P = OuterParse |
1266 | 42 |
|
43 |
fun tuple ((x, y, z), u) = (x, y, z, u) |
|
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
44 |
fun tswap (((x, y), z), u) = (x, y, u, z) |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
45 |
in |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
46 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
47 |
val _ = OuterKeyword.keyword "bind" |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
48 |
val anno_typ = Scan.option (P.name --| P.$$$ "::") -- P.typ |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
(* binding specification *) |
1266 | 51 |
(* maybe use and_list *) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
val bind_parser = |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
53 |
P.enum "," ((P.$$$ "bind" |-- P.term) -- (P.$$$ "in" |-- P.name) >> swap) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
55 |
val constr_parser = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
56 |
P.binding -- Scan.repeat anno_typ |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
57 |
|
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
(* datatype parser *) |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
val dt_parser = |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
60 |
(P.type_args -- P.binding -- P.opt_mixfix >> P.triple1) -- |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
61 |
(P.$$$ "=" |-- P.enum1 "|" (constr_parser -- bind_parser -- P.opt_mixfix >> tswap)) >> tuple |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
(* function equation parser *) |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
val fun_parser = |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
65 |
Scan.optional (P.$$$ "binder" |-- P.fixes -- SpecParse.where_alt_specs) ([],[]) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
66 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
67 |
(* main parser *) |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
68 |
val main_parser = |
1266 | 69 |
(P.and_list1 dt_parser) -- fun_parser >> P.triple2 |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
70 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
71 |
end |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
74 |
(* adds "_raw" to the end of constants and types *) |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
75 |
ML {* |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
76 |
fun add_raw s = s ^ "_raw" |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
77 |
fun add_raws ss = map add_raw ss |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
78 |
fun raw_bind bn = Binding.suffix_name "_raw" bn |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
79 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
80 |
fun replace_str ss s = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
81 |
case (AList.lookup (op=) ss s) of |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
82 |
SOME s' => s' |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
83 |
| NONE => s |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
84 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
85 |
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
86 |
| replace_typ ty_ss T = T |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
87 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
88 |
fun raw_dts ty_ss dts = |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
89 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
90 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
91 |
fun raw_dts_aux1 (bind, tys, mx) = |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
92 |
(raw_bind bind, map (replace_typ ty_ss) tys, mx) |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
93 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
94 |
fun raw_dts_aux2 (ty_args, bind, mx, constrs) = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
95 |
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs) |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
96 |
in |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
97 |
map raw_dts_aux2 dts |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
98 |
end |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
99 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
100 |
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
101 |
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
102 |
| replace_aterm trm_ss trm = trm |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
103 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
104 |
fun replace_term trm_ss ty_ss trm = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
105 |
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
106 |
*} |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
107 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
108 |
ML {* |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
109 |
fun get_cnstrs dts = |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
110 |
map (fn (_, _, _, constrs) => constrs) dts |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
111 |
|
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
112 |
fun get_typed_cnstrs dts = |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
113 |
flat (map (fn (_, bn, _, constrs) => |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
114 |
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
115 |
|
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
116 |
fun get_cnstr_strs dts = |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
117 |
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts)) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
118 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
119 |
fun get_bn_fun_strs bn_funs = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
120 |
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
121 |
*} |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
122 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
123 |
ML {* |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
124 |
fun rawify_dts dt_names dts dts_env = |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
125 |
let |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
126 |
val raw_dts = raw_dts dts_env dts |
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
127 |
val raw_dt_names = add_raws dt_names |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
128 |
in |
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
129 |
(raw_dt_names, raw_dts) |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
130 |
end |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
131 |
*} |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
132 |
|
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
133 |
ML {* |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
134 |
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs = |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
135 |
let |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
136 |
val bn_funs' = map (fn (bn, ty, mx) => |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
137 |
(raw_bind bn, replace_typ dts_env ty, mx)) bn_funs |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
138 |
|
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
139 |
val bn_eqs' = map (fn (attr, trm) => |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
140 |
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
141 |
in |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
142 |
(bn_funs', bn_eqs') |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
143 |
end |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
144 |
*} |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
145 |
|
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
146 |
ML {* |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
147 |
fun rawify_binds dts_env cnstrs_env bn_fun_env binds = |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
148 |
map (map (map (map (fn (opt_trm, i, j) => |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
149 |
(Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env) opt_trm, i, j))))) binds |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
150 |
*} |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
151 |
|
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
152 |
ML {* |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
153 |
fun add_primrec_wrapper funs eqs lthy = |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
154 |
if null funs then (([], []), lthy) |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
155 |
else |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
156 |
let |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
157 |
val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
158 |
val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
159 |
in |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
160 |
Primrec.add_primrec funs' eqs' lthy |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
161 |
end |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
162 |
*} |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
163 |
|
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
164 |
ML {* |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
165 |
fun add_datatype_wrapper dt_names dts = |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
166 |
let |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
167 |
val conf = Datatype.default_config |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
168 |
in |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
169 |
Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts) |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
170 |
end |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
171 |
*} |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
172 |
|
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
173 |
ML {* |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
174 |
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy = |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
175 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
176 |
val thy = ProofContext.theory_of lthy |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
177 |
val thy_name = Context.theory_name thy |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
178 |
|
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
179 |
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
180 |
val dt_full_names = map (Long_Name.qualify thy_name) dt_names |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
181 |
val dt_full_names' = add_raws dt_full_names |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
182 |
val dts_env = dt_full_names ~~ dt_full_names' |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
183 |
|
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
184 |
val cnstrs = get_cnstr_strs dts |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
185 |
val cnstrs_ty = get_typed_cnstrs dts |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
186 |
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
187 |
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
188 |
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty |
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
189 |
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names' |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
190 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
191 |
val bn_fun_strs = get_bn_fun_strs bn_funs |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
192 |
val bn_fun_strs' = add_raws bn_fun_strs |
1266 | 193 |
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs' |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
194 |
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name)) |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
195 |
(bn_fun_strs ~~ bn_fun_strs') |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
196 |
|
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
197 |
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
198 |
|
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
199 |
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
200 |
|
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
201 |
val raw_binds = rawify_binds dts_env cnstrs_env bn_fun_full_env binds |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
202 |
in |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
203 |
lthy |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
204 |
|> add_datatype_wrapper raw_dt_names raw_dts |
1289
02eb0f600630
further code-refactoring in the parser
Christian Urban <urbanc@in.tum.de>
parents:
1287
diff
changeset
|
205 |
||>> add_primrec_wrapper raw_bn_funs raw_bn_eqs |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
206 |
||>> pair raw_binds |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
207 |
end |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
208 |
*} |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
209 |
|
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
210 |
ML {* add_primrec_wrapper *} |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
211 |
|
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
212 |
lemma equivp_hack: "equivp x" |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
213 |
sorry |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
214 |
ML {* |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
215 |
fun equivp_hack ctxt rel = |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
216 |
let |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
217 |
val thy = ProofContext.theory_of ctxt |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
218 |
val ty = domain_type (fastype_of rel) |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
219 |
val cty = ctyp_of thy ty |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
220 |
val ct = cterm_of thy rel |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
221 |
in |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
222 |
Drule.instantiate' [SOME cty] [SOME ct] @{thm equivp_hack} |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
223 |
end |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
224 |
*} |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
225 |
|
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
226 |
ML {* val restricted_nominal=ref true *} |
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
227 |
|
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
228 |
ML {* |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
229 |
fun nominal_datatype2 dts bn_funs bn_eqs binds lthy = |
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
230 |
let |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
231 |
val thy = ProofContext.theory_of lthy |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
232 |
val thy_name = Context.theory_name thy |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
233 |
val (((raw_dt_names, (raw_bn_funs_loc, raw_bn_eqs_loc)), raw_binds), lthy2) = |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
234 |
raw_nominal_decls dts bn_funs bn_eqs binds lthy |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
235 |
val morphism_2_1 = ProofContext.export_morphism lthy2 lthy |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
236 |
val raw_bn_funs = map (Morphism.term morphism_2_1) raw_bn_funs_loc |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
237 |
val raw_bn_eqs = ProofContext.export lthy2 lthy raw_bn_eqs_loc |
1295
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1293
diff
changeset
|
238 |
val dtinfo = Datatype.the_info (ProofContext.theory_of lthy2) (hd raw_dt_names); |
1309 | 239 |
val descr = #descr dtinfo; |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
240 |
val sorts = #sorts dtinfo; |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
241 |
val all_typs = map (fn i => typ_of_dtyp descr sorts (DtRec i)) (map fst descr) |
1309 | 242 |
val all_full_tnames = map (fn (_, (n, _, _)) => n) descr; |
243 |
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy2)) all_full_tnames; |
|
1342 | 244 |
val rel_dtinfos = List.take (dtinfos, (length dts)); |
1309 | 245 |
val inject = flat (map #inject dtinfos); |
246 |
val distinct = flat (map #distinct dtinfos); |
|
1342 | 247 |
val rel_distinct = map #distinct rel_dtinfos; |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
248 |
val induct = #induct dtinfo; |
1309 | 249 |
val inducts = #inducts dtinfo; |
1295
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1293
diff
changeset
|
250 |
val ((raw_perm_def, raw_perm_simps, perms), lthy3) = |
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1293
diff
changeset
|
251 |
Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy2; |
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1293
diff
changeset
|
252 |
val raw_binds_flat = map (map flat) raw_binds; |
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1293
diff
changeset
|
253 |
val (((fv_ts_loc, fv_def_loc), alpha), lthy4) = define_fv_alpha dtinfo raw_binds_flat lthy3; |
1326 | 254 |
val alpha_ts_loc = #preds alpha |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
255 |
val morphism_4_3 = ProofContext.export_morphism lthy4 lthy3; |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
256 |
val fv_ts = map (Morphism.term morphism_4_3) fv_ts_loc; |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
257 |
val alpha_ts = map (Morphism.term morphism_4_3) alpha_ts_loc; |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
258 |
val alpha_induct_loc = #induct alpha |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
259 |
val [alpha_induct] = ProofContext.export lthy4 lthy3 [alpha_induct_loc]; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
260 |
val alpha_inducts = Project_Rule.projects lthy4 (1 upto (length dts)) alpha_induct |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
261 |
val fv_def = ProofContext.export lthy4 lthy3 fv_def_loc; |
1309 | 262 |
val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo); |
263 |
val bn_tys = map (domain_type o fastype_of) raw_bn_funs; |
|
264 |
val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys; |
|
265 |
val bns = raw_bn_funs ~~ bn_nos; |
|
266 |
val alpha_intros = #intrs alpha; |
|
1342 | 267 |
val alpha_cases_loc = #elims alpha |
268 |
val alpha_cases = ProofContext.export lthy4 lthy3 alpha_cases_loc |
|
269 |
val alpha_inj_loc = build_alpha_inj alpha_intros (inject @ distinct) alpha_cases_loc lthy4 |
|
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
270 |
val alpha_inj = ProofContext.export lthy4 lthy3 alpha_inj_loc |
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
271 |
in |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
272 |
if !restricted_nominal then |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
273 |
((raw_dt_names, raw_bn_funs, raw_bn_eqs, raw_binds), lthy4) |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
274 |
else |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
275 |
let |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
276 |
val (bv_eqvts, lthy5) = fold_map (build_bv_eqvt perms (raw_bn_eqs @ raw_perm_def) inducts) bns lthy4; |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
277 |
val (fv_eqvts, lthy6) = build_eqvts Binding.empty fv_ts_loc perms |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
278 |
((flat (map snd bv_eqvts)) @ fv_def_loc @ raw_perm_def) induct lthy5; |
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
279 |
val raw_fv_bv_eqvt_loc = flat (map snd bv_eqvts) @ (snd fv_eqvts) |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
280 |
val raw_fv_bv_eqvt = ProofContext.export lthy6 lthy3 raw_fv_bv_eqvt_loc; |
1331
0f329449e304
Fix eqvt for multiple quantifiers.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1326
diff
changeset
|
281 |
val alpha_eqvt_loc = build_alpha_eqvts alpha_ts_loc perms |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
282 |
(raw_perm_def @ alpha_inj_loc) alpha_induct_loc lthy6; |
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
283 |
val alpha_eqvt = ProofContext.export lthy6 lthy2 alpha_eqvt_loc; |
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
284 |
val alpha_equivp_loc = map (equivp_hack lthy6) alpha_ts_loc |
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1331
diff
changeset
|
285 |
val alpha_equivp_loc = build_equivps alpha_ts_loc induct alpha_induct_loc |
1342 | 286 |
inject alpha_inj_loc distinct alpha_cases_loc alpha_eqvt_loc lthy6; |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
287 |
val alpha_equivp = ProofContext.export lthy6 lthy2 alpha_equivp_loc; |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
288 |
val qty_binds = map (fn (_, b, _, _) => b) dts; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
289 |
val qty_names = map Name.of_binding qty_binds; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
290 |
val qty_full_names = map (Long_Name.qualify thy_name) qty_names |
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1309
diff
changeset
|
291 |
val lthy7 = define_quotient_type |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
292 |
(map (fn ((b, t), alpha) => (([], b, NoSyn), (t, alpha))) ((qty_binds ~~ all_typs) ~~ alpha_ts)) |
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1331
diff
changeset
|
293 |
(ALLGOALS (resolve_tac alpha_equivp)) lthy6; |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
294 |
val const_names = map Name.of_binding (flat (map (fn (_, _, _, t) => map (fn (b, _, _) => b) t) dts)); |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
295 |
val raw_consts = |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
296 |
flat (map (fn (i, (_, _, l)) => |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
297 |
map (fn (cname, dts) => |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
298 |
Const (cname, map (typ_of_dtyp descr sorts) dts ---> |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
299 |
typ_of_dtyp descr sorts (DtRec i))) l) descr); |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
300 |
val (consts_defs, lthy8) = fold_map Quotient_Def.quotient_lift_const (const_names ~~ raw_consts) lthy7; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
301 |
val (consts, const_defs) = split_list consts_defs; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
302 |
val (bns_rsp_pre, lthy9) = fold_map ( |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
303 |
fn (bn_t, i) => prove_const_rsp Binding.empty [bn_t] |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
304 |
(fn _ => fvbv_rsp_tac (nth alpha_inducts i) raw_bn_eqs 1)) bns lthy8; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
305 |
val bns_rsp = flat (map snd bns_rsp_pre); |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
306 |
val ((_, fv_rsp), lthy10) = prove_const_rsp Binding.empty fv_ts |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
307 |
(fn _ => fvbv_rsp_tac alpha_induct fv_def 1) lthy9; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
308 |
val (const_rsps, lthy11) = fold_map (fn cnst => prove_const_rsp Binding.empty [cnst] |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
309 |
(fn _ => constr_rsp_tac alpha_inj (fv_rsp @ bns_rsp) alpha_equivp 1)) raw_consts lthy10 |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
310 |
val (perms_rsp, lthy12) = prove_const_rsp Binding.empty perms |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
311 |
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy11; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
312 |
val qfv_names = map (fn x => "fv_" ^ x) qty_names |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
313 |
val (qfv_defs, lthy12a) = fold_map Quotient_Def.quotient_lift_const (qfv_names ~~ fv_ts) lthy12; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
314 |
val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
315 |
val (qbn_defs, lthy12b) = fold_map Quotient_Def.quotient_lift_const (qbn_names ~~ raw_bn_funs) lthy12a; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
316 |
val thy = Local_Theory.exit_global lthy12b; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
317 |
val perm_names = map (fn x => "permute_" ^ x) qty_names |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
318 |
val thy' = define_lifted_perms qty_full_names (perm_names ~~ perms) raw_perm_simps thy; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
319 |
val lthy13 = Theory_Target.init NONE thy'; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
320 |
val q_name = space_implode "_" qty_names; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
321 |
val q_induct = snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy13, induct)); |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
322 |
val (_, lthy14) = Local_Theory.note ((Binding.name (q_name ^ "_induct"), []), [q_induct]) lthy13; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
323 |
val q_perm = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy14, th))) raw_perm_def; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
324 |
val (_, lthy15) = Local_Theory.note ((Binding.name (q_name ^ "_perm"), []), q_perm) lthy14; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
325 |
val q_fv = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy15, th))) fv_def; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
326 |
val (_, lthy16) = Local_Theory.note ((Binding.name (q_name ^ "_fv"), []), q_fv) lthy15; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
327 |
val q_bn = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy16, th))) raw_bn_eqs; |
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
328 |
val (_, lthy17) = Local_Theory.note ((Binding.name (q_name ^ "_bn"), []), q_bn) lthy16; |
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
329 |
val inj_unfolded = map (LocalDefs.unfold lthy17 @{thms alpha_gen}) alpha_inj |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
330 |
val q_inj_pre = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy17, th))) inj_unfolded; |
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1340
diff
changeset
|
331 |
val q_inj = map (LocalDefs.fold lthy17 @{thms alpha_gen}) q_inj_pre |
1342 | 332 |
val (_, lthy18) = Local_Theory.note ((Binding.name (q_name ^ "_inject"), []), q_inj) lthy17; |
333 |
val rel_dists = flat (map (distinct_rel lthy18 alpha_cases) |
|
334 |
(rel_distinct ~~ (List.take (alpha_ts, (length dts))))) |
|
335 |
val q_dis = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy18, th))) rel_dists; |
|
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
336 |
val (_, lthy19) = Local_Theory.note ((Binding.name (q_name ^ "_distinct"), []), q_dis) lthy18; |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
337 |
val q_eqvt = map (fn th => snd (Quotient_Tacs.lifted_attrib (Context.Proof lthy19, th))) raw_fv_bv_eqvt; |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
338 |
val (_, lthy20) = Local_Theory.note ((Binding.empty, |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
339 |
[Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), q_eqvt) lthy19; |
1293
dca51a1f0c0d
rawified the bind specs (ready to be used now)
Christian Urban <urbanc@in.tum.de>
parents:
1290
diff
changeset
|
340 |
in |
1346
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
341 |
((raw_dt_names, raw_bn_funs, raw_bn_eqs, raw_binds), lthy20) |
998b1bde64e7
Lift fv and bn eqvts; no need to lift alpha_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1342
diff
changeset
|
342 |
end |
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
343 |
end |
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
344 |
*} |
1340
f201eb6acafc
Lift BV,FV,Permutations and injection :).
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1339
diff
changeset
|
345 |
|
1284 | 346 |
ML {* |
347 |
(* parsing the datatypes and declaring *) |
|
348 |
(* constructors in the local theory *) |
|
349 |
fun prepare_dts dt_strs lthy = |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
350 |
let |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
351 |
val thy = ProofContext.theory_of lthy |
1284 | 352 |
|
353 |
fun mk_type full_tname tvrs = |
|
354 |
Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs) |
|
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
355 |
|
1284 | 356 |
fun prep_cnstr lthy full_tname tvs (cname, anno_tys, mx, _) = |
357 |
let |
|
358 |
val tys = map (Syntax.read_typ lthy o snd) anno_tys |
|
359 |
val ty = mk_type full_tname tvs |
|
360 |
in |
|
361 |
((cname, tys ---> ty, mx), (cname, tys, mx)) |
|
362 |
end |
|
363 |
||
364 |
fun prep_dt lthy (tvs, tname, mx, cnstrs) = |
|
365 |
let |
|
366 |
val full_tname = Sign.full_name thy tname |
|
367 |
val (cnstrs', cnstrs'') = |
|
368 |
split_list (map (prep_cnstr lthy full_tname tvs) cnstrs) |
|
369 |
in |
|
370 |
(cnstrs', (tvs, tname, mx, cnstrs'')) |
|
371 |
end |
|
1266 | 372 |
|
1284 | 373 |
val (cnstrs, dts) = |
374 |
split_list (map (prep_dt lthy) dt_strs) |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
375 |
in |
1284 | 376 |
lthy |
377 |
|> Local_Theory.theory (Sign.add_consts_i (flat cnstrs)) |
|
378 |
|> pair dts |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
379 |
end |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
380 |
*} |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
381 |
|
1284 | 382 |
ML {* |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
383 |
(* parsing the binding function specification and *) |
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
384 |
(* declaring the functions in the local theory *) |
1284 | 385 |
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy = |
386 |
let |
|
387 |
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx) |
|
388 |
||
389 |
val ((bn_funs, bn_eqs), _) = |
|
390 |
Specification.read_spec bn_fun_strs bn_eq_strs lthy |
|
391 |
||
392 |
val bn_funs' = map prep_bn_fun bn_funs |
|
393 |
in |
|
394 |
lthy |
|
395 |
|> Local_Theory.theory (Sign.add_consts_i bn_funs') |
|
396 |
|> pair (bn_funs', bn_eqs) |
|
397 |
end |
|
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
398 |
*} |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
399 |
|
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
400 |
ML {* |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
401 |
fun find_all eq xs (k',i) = |
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
402 |
maps (fn (k, (v1, v2)) => if eq (k, k') then [(v1, v2, i)] else []) xs |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
403 |
*} |
1284 | 404 |
|
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
405 |
ML {* |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
406 |
(* associates every SOME with the index in the list; drops NONEs *) |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
407 |
fun mk_env xs = |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
408 |
let |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
409 |
fun mapp (_: int) [] = [] |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
410 |
| mapp i (a :: xs) = |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
411 |
case a of |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
412 |
NONE => mapp (i + 1) xs |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
413 |
| SOME x => (x, i) :: mapp (i + 1) xs |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
414 |
in mapp 0 xs end |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
415 |
*} |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
416 |
|
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
417 |
ML {* |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
418 |
fun env_lookup xs x = |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
419 |
case AList.lookup (op =) xs x of |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
420 |
SOME x => x |
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
421 |
| NONE => error ("cannot find " ^ x ^ " in the binding specification."); |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
422 |
*} |
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
423 |
|
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
424 |
ML {* |
1284 | 425 |
fun prepare_binds dt_strs lthy = |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
426 |
let |
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
427 |
fun extract_annos_binds dt_strs = |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
428 |
map (map (fn (_, antys, _, bns) => (map fst antys, bns))) dt_strs |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
429 |
|
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
430 |
fun prep_bn env bn_str = |
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
431 |
case (Syntax.read_term lthy bn_str) of |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
432 |
Free (x, _) => (NONE, env_lookup env x) |
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
433 |
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), env_lookup env x) |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
434 |
| _ => error (bn_str ^ " not allowed as binding specification."); |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
435 |
|
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
436 |
fun prep_typ env (i, opt_name) = |
1285
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
437 |
case opt_name of |
e3ac56d3b7af
added example from my phd
Christian Urban <urbanc@in.tum.de>
parents:
1284
diff
changeset
|
438 |
NONE => [] |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
439 |
| SOME x => find_all (op=) env (x,i); |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
440 |
|
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
441 |
(* annos - list of annotation for each type (either NONE or SOME fo a type *) |
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
442 |
|
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
443 |
fun prep_binds (annos, bind_strs) = |
1284 | 444 |
let |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
445 |
val env = mk_env annos (* for every label the index *) |
1284 | 446 |
val binds = map (fn (x, y) => (x, prep_bn env y)) bind_strs |
447 |
in |
|
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
448 |
map_index (prep_typ binds) annos |
1284 | 449 |
end |
1287
8557af71724e
slight simplification of the raw-decl generation
Christian Urban <urbanc@in.tum.de>
parents:
1285
diff
changeset
|
450 |
|
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
968
diff
changeset
|
451 |
in |
1290
a7e7ffb7f362
modified for new binding format - hope it is the intended one
Christian Urban <urbanc@in.tum.de>
parents:
1289
diff
changeset
|
452 |
map (map prep_binds) (extract_annos_binds (get_cnstrs dt_strs)) |
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
968
diff
changeset
|
453 |
end |
966
8ba35ce16f7e
Some cleaning of thy vs lthy vs context.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
962
diff
changeset
|
454 |
*} |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
455 |
|
1284 | 456 |
ML {* |
457 |
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy = |
|
458 |
let |
|
459 |
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx) |
|
460 |
||
461 |
val ((dts, (bn_fun, bn_eq)), binds) = |
|
462 |
lthy |
|
463 |
|> Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) |
|
464 |
|> prepare_dts dt_strs |
|
465 |
||>> prepare_bn_funs bn_fun_strs bn_eq_strs |
|
466 |
||> prepare_binds dt_strs |
|
467 |
||
468 |
in |
|
469 |
nominal_datatype2 dts bn_fun bn_eq binds lthy |> snd |
|
470 |
end |
|
471 |
*} |
|
472 |
||
473 |
||
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
474 |
(* Command Keyword *) |
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
parents:
1266
diff
changeset
|
475 |
|
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
476 |
ML {* |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
477 |
let |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
478 |
val kind = OuterKeyword.thy_decl |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
479 |
in |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
480 |
OuterSyntax.local_theory "nominal_datatype" "test" kind |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
481 |
(main_parser >> nominal_datatype2_cmd) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
482 |
end |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
483 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
484 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
485 |
|
961
0f88e04eb486
Variable takes a 'name'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
954
diff
changeset
|
486 |
end |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
487 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
488 |
|
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
489 |