29 * (((term * string option) list * (term * string option)) * (thm option * bool)) list option |
29 * (((term * string option) list * (term * string option)) * (thm option * bool)) list option |
30 val pretty_cert: theory -> cert -> Pretty.T list |
30 val pretty_cert: theory -> cert -> Pretty.T list |
31 |
31 |
32 (*executable code*) |
32 (*executable code*) |
33 type constructors |
33 type constructors |
|
34 type abs_type |
|
35 val type_interpretation: (string -> theory -> theory) -> theory -> theory |
|
36 val datatype_interpretation: (string * constructors -> theory -> theory) -> theory -> theory |
|
37 val abstype_interpretation: (string * abs_type -> theory -> theory) -> theory -> theory |
34 val declare_datatype_global: (string * typ) list -> theory -> theory |
38 val declare_datatype_global: (string * typ) list -> theory -> theory |
35 val declare_datatype_cmd: string list -> theory -> theory |
39 val declare_datatype_cmd: string list -> theory -> theory |
36 val datatype_interpretation: (string * constructors -> theory -> theory) -> theory -> theory |
|
37 type abs_type |
|
38 val declare_abstype: thm -> local_theory -> local_theory |
40 val declare_abstype: thm -> local_theory -> local_theory |
39 val declare_abstype_global: thm -> theory -> theory |
41 val declare_abstype_global: thm -> theory -> theory |
40 val abstype_interpretation: (string * abs_type -> theory -> theory) -> theory -> theory |
|
41 val declare_default_eqns: (thm * bool) list -> local_theory -> local_theory |
42 val declare_default_eqns: (thm * bool) list -> local_theory -> local_theory |
42 val declare_default_eqns_global: (thm * bool) list -> theory -> theory |
43 val declare_default_eqns_global: (thm * bool) list -> theory -> theory |
43 val declare_eqns: (thm * bool) list -> local_theory -> local_theory |
44 val declare_eqns: (thm * bool) list -> local_theory -> local_theory |
44 val declare_eqns_global: (thm * bool) list -> theory -> theory |
45 val declare_eqns_global: (thm * bool) list -> theory -> theory |
45 val add_eqn_global: thm * bool -> theory -> theory |
46 val add_eqn_global: thm * bool -> theory -> theory |
1257 end; |
1258 end; |
1258 |
1259 |
1259 |
1260 |
1260 (** declaration of executable ingredients **) |
1261 (** declaration of executable ingredients **) |
1261 |
1262 |
|
1263 (* plugins for dependent applications *) |
|
1264 |
|
1265 structure Codetype_Plugin = Plugin(type T = string); |
|
1266 |
|
1267 val codetype_plugin = Plugin_Name.declare_setup @{binding codetype}; |
|
1268 |
|
1269 fun type_interpretation f = |
|
1270 Codetype_Plugin.interpretation codetype_plugin |
|
1271 (fn tyco => Local_Theory.background_theory |
|
1272 (fn thy => |
|
1273 thy |
|
1274 |> Sign.root_path |
|
1275 |> Sign.add_path (Long_Name.qualifier tyco) |
|
1276 |> f tyco |
|
1277 |> Sign.restore_naming thy)); |
|
1278 |
|
1279 fun datatype_interpretation f = |
|
1280 type_interpretation (fn tyco => fn thy => |
|
1281 case get_type thy tyco of |
|
1282 (spec, false) => f (tyco, spec) thy |
|
1283 | (_, true) => thy |
|
1284 ); |
|
1285 |
|
1286 fun abstype_interpretation f = |
|
1287 type_interpretation (fn tyco => fn thy => |
|
1288 case try (get_abstype_spec thy) tyco of |
|
1289 SOME spec => f (tyco, spec) thy |
|
1290 | NONE => thy |
|
1291 ); |
|
1292 |
|
1293 fun register_tyco_for_plugin tyco = |
|
1294 Named_Target.theory_map (Codetype_Plugin.data_default tyco); |
|
1295 |
|
1296 |
1262 (* abstract code declarations *) |
1297 (* abstract code declarations *) |
1263 |
1298 |
1264 local |
1299 local |
1265 |
1300 |
1266 fun generic_code_declaration strictness lift_phi f x = |
1301 fun generic_code_declaration strictness lift_phi f x = |
1295 |> map_functions (fold invalidate_abstract_functions_of olds |
1330 |> map_functions (fold invalidate_abstract_functions_of olds |
1296 #> invalidate_constructors_of vs_typ_spec) |
1331 #> invalidate_constructors_of vs_typ_spec) |
1297 |> map_cases (fold invalidate_case_combinators_of olds) |
1332 |> map_cases (fold invalidate_case_combinators_of olds) |
1298 |> map_types (History.register tyco vs_typ_spec) |
1333 |> map_types (History.register tyco vs_typ_spec) |
1299 end; |
1334 end; |
1300 |
|
1301 fun type_interpretation get_spec tyco f = |
|
1302 Local_Theory.background_theory (fn thy => |
|
1303 thy |
|
1304 |> Sign.root_path |
|
1305 |> Sign.add_path (Long_Name.qualifier tyco) |
|
1306 |> f (tyco, get_spec thy tyco) |
|
1307 |> Sign.restore_naming thy); |
|
1308 |
|
1309 structure Datatype_Plugin = Plugin(type T = string); |
|
1310 |
|
1311 val datatype_plugin = Plugin_Name.declare_setup @{binding datatype_code}; |
|
1312 |
|
1313 fun datatype_interpretation f = |
|
1314 Datatype_Plugin.interpretation datatype_plugin |
|
1315 (fn tyco => type_interpretation (fst oo get_type) tyco f); |
|
1316 |
1335 |
1317 fun declare_datatype_global proto_constrs thy = |
1336 fun declare_datatype_global proto_constrs thy = |
1318 let |
1337 let |
1319 fun unoverload_const_typ (c, ty) = |
1338 fun unoverload_const_typ (c, ty) = |
1320 (Axclass.unoverload_const thy (c, ty), ty); |
1339 (Axclass.unoverload_const thy (c, ty), ty); |
1322 val (tyco, (vs, cos)) = constrset_of_consts thy constrs; |
1341 val (tyco, (vs, cos)) = constrset_of_consts thy constrs; |
1323 in |
1342 in |
1324 thy |
1343 thy |
1325 |> modify_specs (register_type |
1344 |> modify_specs (register_type |
1326 (tyco, (vs, Constructors {constructors = cos, case_combinators = []}))) |
1345 (tyco, (vs, Constructors {constructors = cos, case_combinators = []}))) |
1327 |> Named_Target.theory_map (Datatype_Plugin.data_default tyco) |
1346 |> register_tyco_for_plugin tyco |
1328 end; |
1347 end; |
1329 |
1348 |
1330 fun declare_datatype_cmd raw_constrs thy = |
1349 fun declare_datatype_cmd raw_constrs thy = |
1331 declare_datatype_global (map (read_bare_const thy) raw_constrs) thy; |
1350 declare_datatype_global (map (read_bare_const thy) raw_constrs) thy; |
1332 |
|
1333 structure Abstype_Plugin = Plugin(type T = string); |
|
1334 |
|
1335 val abstype_plugin = Plugin_Name.declare_setup @{binding abstype_code}; |
|
1336 |
|
1337 fun abstype_interpretation f = |
|
1338 Abstype_Plugin.interpretation abstype_plugin |
|
1339 (fn tyco => type_interpretation get_abstype_spec tyco f); |
|
1340 |
1351 |
1341 fun generic_declare_abstype strictness proto_thm thy = |
1352 fun generic_declare_abstype strictness proto_thm thy = |
1342 case check_abstype_cert strictness thy proto_thm of |
1353 case check_abstype_cert strictness thy proto_thm of |
1343 SOME (tyco, (vs, (abstractor as (abs, (_, ty)), (proj, abs_rep)))) => |
1354 SOME (tyco, (vs, (abstractor as (abs, (_, ty)), (proj, abs_rep)))) => |
1344 thy |
1355 thy |
1345 |> modify_specs (register_type |
1356 |> modify_specs (register_type |
1346 (tyco, (vs, Abstractor {abstractor = abstractor, projection = proj, abs_rep = abs_rep, more_abstract_functions = []})) |
1357 (tyco, (vs, Abstractor {abstractor = abstractor, projection = proj, abs_rep = abs_rep, more_abstract_functions = []})) |
1347 #> register_fun_spec proj |
1358 #> register_fun_spec proj |
1348 (Proj (Logic.varify_types_global (mk_proj tyco vs ty abs proj), (tyco, abs)))) |
1359 (Proj (Logic.varify_types_global (mk_proj tyco vs ty abs proj), (tyco, abs)))) |
1349 |> Named_Target.theory_map (Abstype_Plugin.data_default tyco) |
1360 |> register_tyco_for_plugin tyco |
1350 | NONE => thy; |
1361 | NONE => thy; |
1351 |
1362 |
1352 val declare_abstype_global = generic_declare_abstype Strict; |
1363 val declare_abstype_global = generic_declare_abstype Strict; |
1353 |
1364 |
1354 val declare_abstype = |
1365 val declare_abstype = |