1941
+ − 1
theory NewParser
2435
+ − 2
imports
+ − 3
"../Nominal-General/Nominal2_Base"
+ − 4
"../Nominal-General/Nominal2_Eqvt"
+ − 5
"../Nominal-General/Nominal2_Supp"
+ − 6
"Nominal2_FSet"
+ − 7
"Abs"
+ − 8
uses ("nominal_dt_rawperm.ML")
+ − 9
("nominal_dt_rawfuns.ML")
+ − 10
("nominal_dt_alpha.ML")
+ − 11
("nominal_dt_quot.ML")
1941
+ − 12
begin
+ − 13
2435
+ − 14
use "nominal_dt_rawperm.ML"
+ − 15
ML {* open Nominal_Dt_RawPerm *}
+ − 16
+ − 17
use "nominal_dt_rawfuns.ML"
+ − 18
ML {* open Nominal_Dt_RawFuns *}
+ − 19
+ − 20
use "nominal_dt_alpha.ML"
+ − 21
ML {* open Nominal_Dt_Alpha *}
+ − 22
+ − 23
use "nominal_dt_quot.ML"
+ − 24
ML {* open Nominal_Dt_Quot *}
+ − 25
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 26
1941
+ − 27
section{* Interface for nominal_datatype *}
+ − 28
2398
+ − 29
ML {*
+ − 30
(* attributes *)
+ − 31
val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add)
+ − 32
val rsp_attrib = Attrib.internal (K Quotient_Info.rsp_rules_add)
+ − 33
+ − 34
*}
+ − 35
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 36
ML {* print_depth 50 *}
1941
+ − 37
+ − 38
ML {*
+ − 39
fun get_cnstrs dts =
+ − 40
map (fn (_, _, _, constrs) => constrs) dts
+ − 41
+ − 42
fun get_typed_cnstrs dts =
+ − 43
flat (map (fn (_, bn, _, constrs) =>
+ − 44
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
+ − 45
+ − 46
fun get_cnstr_strs dts =
+ − 47
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
+ − 48
+ − 49
fun get_bn_fun_strs bn_funs =
+ − 50
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
+ − 51
*}
+ − 52
2106
+ − 53
1944
+ − 54
text {* Infrastructure for adding "_raw" to types and terms *}
+ − 55
1941
+ − 56
ML {*
+ − 57
fun add_raw s = s ^ "_raw"
+ − 58
fun add_raws ss = map add_raw ss
+ − 59
fun raw_bind bn = Binding.suffix_name "_raw" bn
+ − 60
+ − 61
fun replace_str ss s =
+ − 62
case (AList.lookup (op=) ss s) of
+ − 63
SOME s' => s'
+ − 64
| NONE => s
+ − 65
+ − 66
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
+ − 67
| replace_typ ty_ss T = T
+ − 68
+ − 69
fun raw_dts ty_ss dts =
+ − 70
let
+ − 71
fun raw_dts_aux1 (bind, tys, mx) =
+ − 72
(raw_bind bind, map (replace_typ ty_ss) tys, mx)
+ − 73
+ − 74
fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
+ − 75
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
+ − 76
in
+ − 77
map raw_dts_aux2 dts
+ − 78
end
+ − 79
+ − 80
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
+ − 81
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
+ − 82
| replace_aterm trm_ss trm = trm
+ − 83
+ − 84
fun replace_term trm_ss ty_ss trm =
+ − 85
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
+ − 86
*}
+ − 87
+ − 88
ML {*
+ − 89
fun rawify_dts dt_names dts dts_env =
+ − 90
let
+ − 91
val raw_dts = raw_dts dts_env dts
+ − 92
val raw_dt_names = add_raws dt_names
+ − 93
in
+ − 94
(raw_dt_names, raw_dts)
+ − 95
end
+ − 96
*}
+ − 97
+ − 98
ML {*
+ − 99
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 100
let
+ − 101
val bn_funs' = map (fn (bn, ty, mx) =>
2304
+ − 102
(raw_bind bn, SOME (replace_typ dts_env ty), mx)) bn_funs
1941
+ − 103
+ − 104
val bn_eqs' = map (fn (attr, trm) =>
+ − 105
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 106
in
+ − 107
(bn_funs', bn_eqs')
+ − 108
end
+ − 109
*}
+ − 110
+ − 111
ML {*
+ − 112
fun rawify_bclauses dts_env cnstrs_env bn_fun_env bclauses =
+ − 113
let
+ − 114
fun rawify_bnds bnds =
+ − 115
map (apfst (Option.map (replace_term (cnstrs_env @ bn_fun_env) dts_env))) bnds
+ − 116
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 117
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
1941
+ − 118
in
+ − 119
map (map (map rawify_bclause)) bclauses
+ − 120
end
+ − 121
*}
+ − 122
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 123
(* strip_bn_fun takes a rhs of a bn function: this can only contain unions or
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 124
appends of elements; in case of recursive calls it retruns also the applied
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 125
bn function *)
1941
+ − 126
ML {*
2294
+ − 127
fun strip_bn_fun lthy args t =
+ − 128
let
+ − 129
fun aux t =
+ − 130
case t of
+ − 131
Const (@{const_name sup}, _) $ l $ r => aux l @ aux r
+ − 132
| Const (@{const_name append}, _) $ l $ r => aux l @ aux r
+ − 133
| Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 134
(find_index (equal x) args, NONE) :: aux y
+ − 135
| Const (@{const_name Cons}, _) $ (Const (@{const_name atom}, _) $ (x as Var _)) $ y =>
+ − 136
(find_index (equal x) args, NONE) :: aux y
+ − 137
| Const (@{const_name bot}, _) => []
+ − 138
| Const (@{const_name Nil}, _) => []
+ − 139
| (f as Const _) $ (x as Var _) => [(find_index (equal x) args, SOME f)]
+ − 140
| _ => error ("Unsupported binding function: " ^ (Syntax.string_of_term lthy t))
+ − 141
in
+ − 142
aux t
+ − 143
end
1941
+ − 144
*}
+ − 145
+ − 146
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 147
(** definition of the raw binding functions **)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 148
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 149
(* TODO: needs cleaning *)
1941
+ − 150
fun find [] _ = error ("cannot find element")
+ − 151
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y
+ − 152
2295
+ − 153
fun prep_bn_info lthy dt_names dts eqs =
1941
+ − 154
let
+ − 155
fun aux eq =
+ − 156
let
+ − 157
val (lhs, rhs) = eq
+ − 158
|> HOLogic.dest_Trueprop
+ − 159
|> HOLogic.dest_eq
+ − 160
val (bn_fun, [cnstr]) = strip_comb lhs
2294
+ − 161
val (_, ty) = dest_Const bn_fun
1941
+ − 162
val (ty_name, _) = dest_Type (domain_type ty)
+ − 163
val dt_index = find_index (fn x => x = ty_name) dt_names
2294
+ − 164
val (cnstr_head, cnstr_args) = strip_comb cnstr
+ − 165
val rhs_elements = strip_bn_fun lthy cnstr_args rhs
1941
+ − 166
in
2308
+ − 167
(dt_index, (bn_fun, (cnstr_head, rhs_elements)))
2122
+ − 168
end
1941
+ − 169
fun order dts i ts =
+ − 170
let
+ − 171
val dt = nth dts i
+ − 172
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt)
+ − 173
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts
+ − 174
in
+ − 175
map (find ts') cts
+ − 176
end
+ − 177
+ − 178
val unordered = AList.group (op=) (map aux eqs)
+ − 179
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered
+ − 180
val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered'
2118
+ − 181
val ordered' = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) ordered)
2122
+ − 182
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 183
(*val _ = tracing ("eqs\n" ^ cat_lines (map (Syntax.string_of_term lthy) eqs))*)
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 184
(*val _ = tracing ("map eqs\n" ^ @{make_string} (map aux2 eqs))*)
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 185
(*val _ = tracing ("ordered'\n" ^ @{make_string} ordered')*)
1941
+ − 186
in
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 187
ordered'
1941
+ − 188
end
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 189
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 190
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 191
fun define_raw_bns dt_names dts raw_bn_funs raw_bn_eqs constr_thms size_thms lthy =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 192
if null raw_bn_funs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 193
then ([], [], [], [], lthy)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 194
else
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 195
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 196
val (_, lthy1) = Function.add_function raw_bn_funs raw_bn_eqs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 197
Function_Common.default_config (pat_completeness_simp constr_thms) lthy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 198
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 199
val (info, lthy2) = prove_termination size_thms (Local_Theory.restore lthy1)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 200
val {fs, simps, inducts, ...} = info
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 201
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 202
val raw_bn_induct = (the inducts)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 203
val raw_bn_eqs = the simps
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 204
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 205
val raw_bn_info =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 206
prep_bn_info lthy dt_names dts (map prop_of raw_bn_eqs)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 207
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 208
(fs, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy2)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 209
end
1941
+ − 210
*}
+ − 211
+ − 212
ML {*
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 213
fun define_raw_dts dts bn_funs bn_eqs binds lthy =
1941
+ − 214
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 215
val thy = Local_Theory.exit_global lthy
1941
+ − 216
val thy_name = Context.theory_name thy
+ − 217
+ − 218
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 219
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 220
val dt_full_names' = add_raws dt_full_names
+ − 221
val dts_env = dt_full_names ~~ dt_full_names'
+ − 222
+ − 223
val cnstrs = get_cnstr_strs dts
+ − 224
val cnstrs_ty = get_typed_cnstrs dts
+ − 225
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
+ − 226
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 227
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
+ − 228
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
+ − 229
+ − 230
val bn_fun_strs = get_bn_fun_strs bn_funs
+ − 231
val bn_fun_strs' = add_raws bn_fun_strs
+ − 232
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
+ − 233
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 234
(bn_fun_strs ~~ bn_fun_strs')
+ − 235
+ − 236
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
+ − 237
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
+ − 238
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env binds
+ − 239
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 240
val (raw_dt_full_names, thy1) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 241
Datatype.add_datatype Datatype.default_config raw_dt_names raw_dts thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 242
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 243
val lthy1 = Named_Target.theory_init thy1
2304
+ − 244
in
2337
+ − 245
(raw_dt_full_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy1)
2304
+ − 246
end
+ − 247
*}
+ − 248
+ − 249
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 250
ML {*
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 251
(* for testing porposes - to exit the procedure early *)
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 252
exception TEST of Proof.context
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 253
2436
+ − 254
val (STEPS, STEPS_setup) = Attrib.config_int "STEPS" (K 100);
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 255
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 256
fun get_STEPS ctxt = Config.get ctxt STEPS
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 257
*}
2008
1bddffddc03f
attempted to remove dependency on (old) Fv and (old) Parser; lifting still uses Fv.thy; the examples do not work at the moment (with equivp proofs failing)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 258
2125
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 259
setup STEPS_setup
60ee289a8c63
made out of STEPS a configuration value so that it can be set individually in each file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 260
1941
+ − 261
ML {*
2436
+ − 262
fun nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses lthy =
1941
+ − 263
let
2294
+ − 264
(* definition of the raw datatypes *)
2316
+ − 265
val _ = warning "Definition of raw datatypes";
2337
+ − 266
val (raw_dt_names, raw_dts, raw_bclauses, raw_bn_funs, raw_bn_eqs, lthy0) =
2308
+ − 267
if get_STEPS lthy > 0
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 268
then define_raw_dts dts bn_funs bn_eqs bclauses lthy
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 269
else raise TEST lthy
1941
+ − 270
2304
+ − 271
val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names)
2143
871d8a5e0c67
somewhat simplified the main parsing function; failed to move a Note-statement to define_raw_perms
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 272
val {descr, sorts, ...} = dtinfo
2407
+ − 273
2400
+ − 274
val raw_tys = all_dtyps descr sorts
+ − 275
val raw_full_ty_names = map (fst o dest_Type) raw_tys
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 276
val tvs = hd raw_tys
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 277
|> snd o dest_Type
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 278
|> map dest_TFree
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 279
2400
+ − 280
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names
+ − 281
2407
+ − 282
val raw_cns_info = all_dtyp_constrs_types descr sorts
+ − 283
val raw_constrs = flat (map (map (fn (c, _, _, _) => c)) raw_cns_info)
+ − 284
2400
+ − 285
val raw_inject_thms = flat (map #inject dtinfos)
+ − 286
val raw_distinct_thms = flat (map #distinct dtinfos)
+ − 287
val raw_induct_thm = #induct dtinfo
+ − 288
val raw_induct_thms = #inducts dtinfo
+ − 289
val raw_exhaust_thms = map #exhaust dtinfos
+ − 290
val raw_size_trms = map size_const raw_tys
2388
+ − 291
val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names)
+ − 292
|> `(fn thms => (length thms) div 2)
2392
+ − 293
|> uncurry drop
2388
+ − 294
2409
+ − 295
(* definitions of raw permutations by primitive recursion *)
2316
+ − 296
val _ = warning "Definition of raw permutations";
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 297
val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2a) =
2308
+ − 298
if get_STEPS lthy0 > 1
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 299
then define_raw_perms raw_full_ty_names raw_tys tvs raw_constrs raw_induct_thm lthy0
2308
+ − 300
else raise TEST lthy0
2144
+ − 301
+ − 302
(* noting the raw permutations as eqvt theorems *)
2398
+ − 303
val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2a
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 304
2142
c39d4fe31100
moved the exporting part into the parser (this is still a hack); re-added CoreHaskell again to the examples - there seems to be a problem with the variable name pat
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 305
(* definition of raw fv_functions *)
2316
+ − 306
val _ = warning "Definition of raw fv-functions";
2405
+ − 307
val (raw_bns, raw_bn_defs, raw_bn_info, raw_bn_induct, lthy3a) =
2308
+ − 308
if get_STEPS lthy3 > 2
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 309
then define_raw_bns raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 310
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 311
else raise TEST lthy3
2292
+ − 312
2308
+ − 313
val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) =
+ − 314
if get_STEPS lthy3a > 3
2407
+ − 315
then define_raw_fvs raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 316
(raw_inject_thms @ raw_distinct_thms) raw_size_thms lthy3a
2308
+ − 317
else raise TEST lthy3a
+ − 318
2011
12ce87b55f97
tried to add some comments in the huge(!) nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 319
(* definition of raw alphas *)
2316
+ − 320
val _ = warning "Definition of alphas";
2300
+ − 321
val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) =
2308
+ − 322
if get_STEPS lthy3b > 4
2407
+ − 323
then define_raw_alpha raw_full_ty_names raw_tys raw_cns_info raw_bn_info raw_bclauses raw_fvs lthy3b
2308
+ − 324
else raise TEST lthy3b
2336
+ − 325
val alpha_tys = map (domain_type o fastype_of) alpha_trms
+ − 326
2300
+ − 327
(* definition of alpha-distinct lemmas *)
2316
+ − 328
val _ = warning "Distinct theorems";
2399
+ − 329
val alpha_distincts =
2400
+ − 330
mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys
2300
+ − 331
2361
+ − 332
(* definition of alpha_eq_iff lemmas *)
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 333
(* they have a funny shape for the simplifier ---- CHECK WHETHER NEEDED*)
2316
+ − 334
val _ = warning "Eq-iff theorems";
2387
+ − 335
val (alpha_eq_iff_simps, alpha_eq_iff) =
2295
+ − 336
if get_STEPS lthy > 5
2400
+ − 337
then mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases
2295
+ − 338
else raise TEST lthy4
2022
+ − 339
2388
+ − 340
(* proving equivariance lemmas for bns, fvs, size and alpha *)
2001
7c8242a02f39
NewParser with Parser functionality, but some cheats included since the order of datayupes is wrong.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 341
val _ = warning "Proving equivariance";
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 342
val raw_bn_eqvt =
2298
+ − 343
if get_STEPS lthy > 6
2405
+ − 344
then raw_prove_eqvt raw_bns raw_bn_induct (raw_bn_defs @ raw_perm_simps) lthy4
2298
+ − 345
else raise TEST lthy4
+ − 346
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 347
(* noting the raw_bn_eqvt lemmas in a temprorary theory *)
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 348
val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_bn_eqvt) lthy4)
2305
+ − 349
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 350
val raw_fv_eqvt =
2298
+ − 351
if get_STEPS lthy > 7
2384
+ − 352
then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps)
2388
+ − 353
(Local_Theory.restore lthy_tmp)
+ − 354
else raise TEST lthy4
+ − 355
2389
+ − 356
val raw_size_eqvt =
2388
+ − 357
if get_STEPS lthy > 8
+ − 358
then raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps)
+ − 359
(Local_Theory.restore lthy_tmp)
2389
+ − 360
|> map (rewrite_rule @{thms permute_nat_def[THEN eq_reflection]})
+ − 361
|> map (fn thm => thm RS @{thm sym})
2305
+ − 362
else raise TEST lthy4
+ − 363
2406
428d9cb9a243
can also lift the various eqvt lemmas for bn, fv, fv_bn and size
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 364
val lthy5 = snd (Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_fv_eqvt) lthy_tmp)
2306
+ − 365
2336
+ − 366
val (alpha_eqvt, lthy6) =
2388
+ − 367
if get_STEPS lthy > 9
2336
+ − 368
then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5
2311
+ − 369
else raise TEST lthy4
+ − 370
+ − 371
(* proving alpha equivalence *)
+ − 372
val _ = warning "Proving equivalence"
+ − 373
2316
+ − 374
val alpha_refl_thms =
2388
+ − 375
if get_STEPS lthy > 10
+ − 376
then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6
2336
+ − 377
else raise TEST lthy6
2316
+ − 378
2311
+ − 379
val alpha_sym_thms =
2388
+ − 380
if get_STEPS lthy > 11
2336
+ − 381
then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6
+ − 382
else raise TEST lthy6
2298
+ − 383
2311
+ − 384
val alpha_trans_thms =
2388
+ − 385
if get_STEPS lthy > 12
2400
+ − 386
then raw_prove_trans (alpha_trms @ alpha_bn_trms) (raw_distinct_thms @ raw_inject_thms)
2336
+ − 387
alpha_intros alpha_induct alpha_cases lthy6
+ − 388
else raise TEST lthy6
2311
+ − 389
2404
+ − 390
val (alpha_equivp_thms, alpha_bn_equivp_thms) =
2388
+ − 391
if get_STEPS lthy > 13
2404
+ − 392
then raw_prove_equivp alpha_trms alpha_bn_trms alpha_refl_thms alpha_sym_thms
+ − 393
alpha_trans_thms lthy6
2336
+ − 394
else raise TEST lthy6
2322
+ − 395
2320
+ − 396
(* proving alpha implies alpha_bn *)
+ − 397
val _ = warning "Proving alpha implies bn"
+ − 398
+ − 399
val alpha_bn_imp_thms =
2388
+ − 400
if get_STEPS lthy > 14
2336
+ − 401
then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6
+ − 402
else raise TEST lthy6
2322
+ − 403
2397
+ − 404
(* respectfulness proofs *)
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
val raw_funs_rsp_aux =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
if get_STEPS lthy > 15
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
then raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 408
raw_bns raw_fv_bns alpha_induct (raw_bn_defs @ raw_fv_defs) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
else raise TEST lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
val raw_funs_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
if get_STEPS lthy > 16
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
then map mk_funs_rsp raw_funs_rsp_aux
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 414
else raise TEST lthy6
2388
+ − 415
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 416
val raw_size_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 417
if get_STEPS lthy > 17
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 418
then
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 419
raw_size_rsp_aux (alpha_trms @ alpha_bn_trms) alpha_induct
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 420
(raw_size_thms @ raw_size_eqvt) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 421
|> map mk_funs_rsp
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 422
else raise TEST lthy6
2392
+ − 423
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 424
val raw_constrs_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 425
if get_STEPS lthy > 18
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 426
then raw_constrs_rsp raw_constrs alpha_trms alpha_intros
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 427
(alpha_bn_imp_thms @ raw_funs_rsp_aux) lthy6
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 428
else raise TEST lthy6
2397
+ − 429
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 430
val alpha_permute_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
if get_STEPS lthy > 19
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 432
then map mk_alpha_permute_rsp alpha_eqvt
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 433
else raise TEST lthy6
2384
+ − 434
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 435
val alpha_bn_rsp =
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 436
if get_STEPS lthy > 20
2440
0a36825b16c1
"isabelle make test" makes all major examples....they work up to supp theorems (excluding)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 437
then raw_alpha_bn_rsp alpha_bn_trms alpha_bn_equivp_thms alpha_bn_imp_thms
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 438
else raise TEST lthy6
2404
+ − 439
2398
+ − 440
(* noting the quot_respects lemmas *)
+ − 441
val (_, lthy6a) =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 442
if get_STEPS lthy > 21
2398
+ − 443
then Local_Theory.note ((Binding.empty, [rsp_attrib]),
2404
+ − 444
raw_constrs_rsp @ raw_funs_rsp @ raw_size_rsp @ alpha_permute_rsp @ alpha_bn_rsp) lthy6
2398
+ − 445
else raise TEST lthy6
+ − 446
2336
+ − 447
(* defining the quotient type *)
+ − 448
val _ = warning "Declaring the quotient types"
+ − 449
val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts
2400
+ − 450
2336
+ − 451
val (qty_infos, lthy7) =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 452
if get_STEPS lthy > 22
2400
+ − 453
then define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a
2398
+ − 454
else raise TEST lthy6a
2336
+ − 455
+ − 456
val qtys = map #qtyp qty_infos
2400
+ − 457
val qty_full_names = map (fst o dest_Type) qtys
+ − 458
val qty_names = map Long_Name.base_name qty_full_names
+ − 459
2339
+ − 460
(* defining of quotient term-constructors, binding functions, free vars functions *)
2378
+ − 461
val _ = warning "Defining the quotient constants"
2346
+ − 462
val qconstrs_descr =
2338
+ − 463
flat (map (fn (_, _, _, cs) => map (fn (b, _, mx) => (Name.of_binding b, mx)) cs) dts)
2400
+ − 464
|> map2 (fn t => fn (b, mx) => (b, t, mx)) raw_constrs
2338
+ − 465
2339
+ − 466
val qbns_descr =
2346
+ − 467
map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns
2339
+ − 468
+ − 469
val qfvs_descr =
2346
+ − 470
map2 (fn n => fn t => ("fv_" ^ n, t, NoSyn)) qty_names raw_fvs
2339
+ − 471
2346
+ − 472
val qfv_bns_descr =
2398
+ − 473
map2 (fn (b, _, _) => fn t => ("fv_" ^ Name.of_binding b, t, NoSyn)) bn_funs raw_fv_bns
2339
+ − 474
2384
+ − 475
val qalpha_bns_descr =
+ − 476
map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs alpha_bn_trms
+ − 477
2398
+ − 478
val qperm_descr =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 479
map2 (fn n => fn t => ("permute_" ^ n, Type.legacy_freeze t, NoSyn)) qty_names raw_perm_funs
2398
+ − 480
2400
+ − 481
val qsize_descr =
+ − 482
map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms
+ − 483
2384
+ − 484
val (((((qconstrs_info, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), lthy8) =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 485
if get_STEPS lthy > 23
2346
+ − 486
then
+ − 487
lthy7
2400
+ − 488
|> define_qconsts qtys qconstrs_descr
+ − 489
||>> define_qconsts qtys qbns_descr
+ − 490
||>> define_qconsts qtys qfvs_descr
+ − 491
||>> define_qconsts qtys qfv_bns_descr
+ − 492
||>> define_qconsts qtys qalpha_bns_descr
2338
+ − 493
else raise TEST lthy7
+ − 494
2400
+ − 495
(* definition of the quotient permfunctions and pt-class *)
+ − 496
val lthy9 =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 497
if get_STEPS lthy > 24
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 498
then define_qperms qtys qty_full_names tvs qperm_descr raw_perm_laws lthy8
2400
+ − 499
else raise TEST lthy8
+ − 500
2401
7645e18e8b19
modified the code for class instantiations (with help from Florian)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 501
val lthy9a =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 502
if get_STEPS lthy > 25
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 503
then define_qsizes qtys qty_full_names tvs qsize_descr lthy9
2400
+ − 504
else raise TEST lthy9
2398
+ − 505
2346
+ − 506
val qconstrs = map #qconst qconstrs_info
+ − 507
val qbns = map #qconst qbns_info
+ − 508
val qfvs = map #qconst qfvs_info
+ − 509
val qfv_bns = map #qconst qfv_bns_info
2384
+ − 510
val qalpha_bns = map #qconst qalpha_bns_info
2434
+ − 511
+ − 512
(* lifting of the theorems *)
+ − 513
val _ = warning "Lifting of Theorems"
+ − 514
+ − 515
val eq_iff_simps = @{thms alphas permute_prod.simps prod_fv.simps prod_alpha_def prod_rel.simps
+ − 516
prod.cases}
+ − 517
+ − 518
val ((((((qdistincts, qeq_iffs), qfv_defs), qbn_defs), qperm_simps), qfv_qbn_eqvts), lthyA) =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 519
if get_STEPS lthy > 26
2434
+ − 520
then
+ − 521
lthy9a
+ − 522
|> lift_thms qtys [] alpha_distincts
+ − 523
||>> lift_thms qtys eq_iff_simps alpha_eq_iff
+ − 524
||>> lift_thms qtys [] raw_fv_defs
+ − 525
||>> lift_thms qtys [] raw_bn_defs
+ − 526
||>> lift_thms qtys [] raw_perm_simps
+ − 527
||>> lift_thms qtys [] (raw_fv_eqvt @ raw_bn_eqvt)
+ − 528
else raise TEST lthy9a
+ − 529
+ − 530
val (((qsize_eqvt, [qinduct]), qexhausts), lthyB) =
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 531
if get_STEPS lthy > 27
2434
+ − 532
then
+ − 533
lthyA
+ − 534
|> lift_thms qtys [] raw_size_eqvt
+ − 535
||>> lift_thms qtys [] [raw_induct_thm]
+ − 536
||>> lift_thms qtys [] raw_exhaust_thms
+ − 537
else raise TEST lthyA
+ − 538
2436
+ − 539
(* noting the theorems *)
+ − 540
+ − 541
(* generating the prefix for the theorem names *)
+ − 542
val thms_name =
+ − 543
the_default (Binding.name (space_implode "_" qty_names)) opt_thms_name
+ − 544
fun thms_suffix s = Binding.qualified true s thms_name
+ − 545
2434
+ − 546
val (_, lthy9') = lthyB
2436
+ − 547
|> Local_Theory.note ((thms_suffix "distinct", []), qdistincts)
+ − 548
||>> Local_Theory.note ((thms_suffix "eq_iff", []), qeq_iffs)
+ − 549
||>> Local_Theory.note ((thms_suffix "fv_defs", []), qfv_defs)
+ − 550
||>> Local_Theory.note ((thms_suffix "bn_defs", []), qbn_defs)
+ − 551
||>> Local_Theory.note ((thms_suffix "perm_simps", []), qperm_simps)
+ − 552
||>> Local_Theory.note ((thms_suffix "fv_bn_eqvt", []), qfv_qbn_eqvts)
+ − 553
||>> Local_Theory.note ((thms_suffix "size_eqvt", []), qsize_eqvt)
+ − 554
||>> Local_Theory.note ((thms_suffix "induct", []), [qinduct])
+ − 555
||>> Local_Theory.note ((thms_suffix "exhaust", []), qexhausts)
2434
+ − 556
1941
+ − 557
in
2435
+ − 558
(0, lthy9')
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 559
end handle TEST ctxt => (0, ctxt)
1941
+ − 560
*}
+ − 561
+ − 562
section {* Preparing and parsing of the specification *}
+ − 563
+ − 564
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 565
(* generates the parsed datatypes and
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 566
declares the constructors
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 567
*)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 568
fun prepare_dts dt_strs thy =
1941
+ − 569
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 570
fun inter_fs_sort thy (a, S) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 571
(a, Type.inter_sort (Sign.tsig_of thy) (@{sort fs}, S))
1941
+ − 572
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 573
fun mk_type tname sorts (cname, cargs, mx) =
1941
+ − 574
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 575
val full_tname = Sign.full_name thy tname
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 576
val ty = Type (full_tname, map (TFree o inter_fs_sort thy) sorts)
1941
+ − 577
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 578
(cname, cargs ---> ty, mx)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 579
end
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 580
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 581
fun prep_constr (cname, cargs, mx, _) (constrs, sorts) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 582
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 583
val (cargs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 584
fold_map (Datatype.read_typ thy) (map snd cargs) sorts
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 585
|>> map (map_type_tfree (TFree o inter_fs_sort thy))
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 586
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 587
(constrs @ [(cname, cargs', mx)], sorts')
1941
+ − 588
end
+ − 589
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 590
fun prep_dts (tvs, tname, mx, constrs) (constr_trms, dts, sorts) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 591
let
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 592
val (constrs', sorts') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 593
fold prep_constr constrs ([], sorts)
1941
+ − 594
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 595
val constr_trms' =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 596
map (mk_type tname (rev sorts')) constrs'
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 597
in
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 598
(constr_trms @ constr_trms', dts @ [(tvs, tname, mx, constrs')], sorts')
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 599
end
2425
+ − 600
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 601
val (constr_trms, dts, sorts) = fold prep_dts dt_strs ([], [], []);
1941
+ − 602
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 603
thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 604
|> Sign.add_consts_i constr_trms
1941
+ − 605
|> pair dts
+ − 606
end
+ − 607
*}
+ − 608
+ − 609
ML {*
+ − 610
(* parsing the binding function specification and *)
+ − 611
(* declaring the functions in the local theory *)
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 612
fun prepare_bn_funs bn_fun_strs bn_eq_strs thy =
1941
+ − 613
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 614
val lthy = Named_Target.theory_init thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 615
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 616
val ((bn_funs, bn_eqs), lthy') =
1941
+ − 617
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 618
+ − 619
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
+ − 620
+ − 621
val bn_funs' = map prep_bn_fun bn_funs
+ − 622
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 623
(Local_Theory.exit_global lthy')
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 624
|> Sign.add_consts_i bn_funs'
1941
+ − 625
|> pair (bn_funs', bn_eqs)
+ − 626
end
+ − 627
*}
+ − 628
+ − 629
text {* associates every SOME with the index in the list; drops NONEs *}
+ − 630
ML {*
+ − 631
fun indexify xs =
+ − 632
let
+ − 633
fun mapp _ [] = []
+ − 634
| mapp i (NONE :: xs) = mapp (i + 1) xs
+ − 635
| mapp i (SOME x :: xs) = (x, i) :: mapp (i + 1) xs
+ − 636
in
+ − 637
mapp 0 xs
+ − 638
end
+ − 639
+ − 640
fun index_lookup xs x =
+ − 641
case AList.lookup (op=) xs x of
+ − 642
SOME x => x
+ − 643
| NONE => error ("Cannot find " ^ x ^ " as argument annotation.");
+ − 644
*}
+ − 645
+ − 646
ML {*
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 647
fun prepare_bclauses dt_strs thy =
1941
+ − 648
let
+ − 649
val annos_bclauses =
+ − 650
get_cnstrs dt_strs
+ − 651
|> map (map (fn (_, antys, _, bns) => (map fst antys, bns)))
+ − 652
+ − 653
fun prep_binder env bn_str =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 654
case (Syntax.read_term_global thy bn_str) of
1941
+ − 655
Free (x, _) => (NONE, index_lookup env x)
+ − 656
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T)), index_lookup env x)
+ − 657
| _ => error ("The term " ^ bn_str ^ " is not allowed as binding function.")
+ − 658
+ − 659
fun prep_body env bn_str = index_lookup env bn_str
+ − 660
+ − 661
fun prep_bclause env (mode, binders, bodies) =
+ − 662
let
+ − 663
val binders' = map (prep_binder env) binders
+ − 664
val bodies' = map (prep_body env) bodies
+ − 665
in
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 666
BC (mode, binders', bodies')
1941
+ − 667
end
+ − 668
+ − 669
fun prep_bclauses (annos, bclause_strs) =
+ − 670
let
+ − 671
val env = indexify annos (* for every label, associate the index *)
+ − 672
in
+ − 673
map (prep_bclause env) bclause_strs
+ − 674
end
+ − 675
in
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 676
(map (map prep_bclauses) annos_bclauses, thy)
1941
+ − 677
end
+ − 678
*}
+ − 679
1943
+ − 680
text {*
+ − 681
adds an empty binding clause for every argument
+ − 682
that is not already part of a binding clause
+ − 683
*}
+ − 684
1941
+ − 685
ML {*
+ − 686
fun included i bcs =
+ − 687
let
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 688
fun incl (BC (_, bns, bds)) =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 689
member (op =) (map snd bns) i orelse member (op =) bds i
1941
+ − 690
in
+ − 691
exists incl bcs
+ − 692
end
+ − 693
*}
+ − 694
+ − 695
ML {*
+ − 696
fun complete dt_strs bclauses =
+ − 697
let
+ − 698
val args =
+ − 699
get_cnstrs dt_strs
+ − 700
|> map (map (fn (_, antys, _, _) => length antys))
+ − 701
+ − 702
fun complt n bcs =
+ − 703
let
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 704
fun add bcs i = (if included i bcs then [] else [BC (Lst, [], [i])])
1941
+ − 705
in
+ − 706
bcs @ (flat (map_range (add bcs) n))
+ − 707
end
+ − 708
in
+ − 709
map2 (map2 complt) args bclauses
+ − 710
end
+ − 711
*}
+ − 712
+ − 713
ML {*
2436
+ − 714
fun nominal_datatype2_cmd (opt_thms_name, dt_strs, bn_fun_strs, bn_eq_strs) lthy =
1941
+ − 715
let
2436
+ − 716
val pre_typs =
+ − 717
map (fn (tvs, tname, mx, _) => (tname, length tvs, mx)) dt_strs
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 718
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 719
(* this theory is used just for parsing *)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 720
val thy = ProofContext.theory_of lthy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 721
val tmp_thy = Theory.copy thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 722
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 723
val (((dts, (bn_funs, bn_eqs)), bclauses), tmp_thy') =
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 724
tmp_thy
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 725
|> Sign.add_types pre_typs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 726
|> prepare_dts dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 727
||>> prepare_bn_funs bn_fun_strs bn_eq_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 728
||>> prepare_bclauses dt_strs
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 729
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 730
val bclauses' = complete dt_strs bclauses
1941
+ − 731
in
2436
+ − 732
timeit (fn () => nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy |> snd)
1941
+ − 733
end
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 734
*}
1941
+ − 735
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 736
ML {*
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 737
(* nominal datatype parser *)
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 738
local
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 739
structure P = Parse;
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 740
structure S = Scan
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 741
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 742
fun triple ((x, y), z) = (x, y, z)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 743
fun tuple1 ((x, y, z), u) = (x, y, z, u)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 744
fun tuple2 (((x, y), z), u) = (x, y, u, z)
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 745
fun tuple3 ((x, y), (z, u)) = (x, y, z, u)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 746
in
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 747
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 748
val _ = Keyword.keyword "bind"
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 749
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 750
val opt_name = Scan.option (P.binding --| Args.colon)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 751
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 752
val anno_typ = S.option (P.name --| P.$$$ "::") -- P.typ
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 753
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 754
val bind_mode = P.$$$ "bind" |--
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 755
S.optional (Args.parens
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 756
(Args.$$$ "list" >> K Lst || Args.$$$ "set" >> K Set || Args.$$$ "res" >> K Res)) Lst
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 757
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 758
val bind_clauses =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 759
P.enum "," (bind_mode -- S.repeat1 P.term -- (P.$$$ "in" |-- S.repeat1 P.name) >> triple)
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 760
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 761
val cnstr_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 762
P.binding -- S.repeat anno_typ -- bind_clauses -- P.opt_mixfix >> tuple2
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 763
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 764
(* datatype parser *)
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 765
val dt_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 766
(P.type_args -- P.binding -- P.opt_mixfix >> triple) --
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 767
(P.$$$ "=" |-- P.enum1 "|" cnstr_parser) >> tuple1
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 768
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 769
(* binding function parser *)
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 770
val bnfun_parser =
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 771
S.optional (P.$$$ "binder" |-- P.fixes -- Parse_Spec.where_alt_specs) ([], [])
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 772
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 773
(* main parser *)
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 774
val main_parser =
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 775
opt_name -- P.and_list1 dt_parser -- bnfun_parser >> tuple3
2424
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 776
621ebd8b13c4
changed parser so that the binding mode is indicated as "bind (list)", "bind (set)" or "bind (res)"; if only "bind" is given, then bind (list) is assumed as default
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 777
end
1941
+ − 778
+ − 779
(* Command Keyword *)
2168
+ − 780
val _ = Outer_Syntax.local_theory "nominal_datatype" "test" Keyword.thy_decl
1941
+ − 781
(main_parser >> nominal_datatype2_cmd)
+ − 782
*}
+ − 783
2292
+ − 784
1941
+ − 785
end
+ − 786
+ − 787
+ − 788