generalized datatype code generation code so that it works with old-style and new-style (co)datatypes (as long as they are not local)
1 (* Title: HOL/Tools/Datatype/datatype_codegen.ML
2 Author: Stefan Berghofer and Florian Haftmann, TU Muenchen
4 Code generator facilities for inductive datatypes.
7 signature DATATYPE_CODEGEN =
11 structure Datatype_Codegen : DATATYPE_CODEGEN =
14 fun add_code_for_datatype fcT_name thy =
16 val (As', ctr_specs) = Datatype_Data.the_spec thy fcT_name;
17 val {inject = inject_thms, distinct = distinct_thms, case_rewrites = case_thms, ...} =
18 Datatype_Data.the_info thy fcT_name;
20 val As = map TFree As';
21 val fcT = Type (fcT_name, As);
22 val ctrs = map (fn (c, arg_Ts) => (c, arg_Ts ---> fcT)) ctr_specs;
24 Ctr_Sugar_Code.add_ctr_code fcT_name As ctrs inject_thms distinct_thms case_thms thy
27 val _ = Theory.setup (Datatype_Data.interpretation (K (fold add_code_for_datatype)));