src/HOL/Tools/Datatype/datatype_codegen.ML
author blanchet
Mon, 02 Dec 2013 20:31:54 +0100
changeset 55988 62fb5af93fe2
parent 53925 da1fdbfebd39
child 56743 f33536723999
permissions -rw-r--r--
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
     3 
     4 Code generator facilities for inductive datatypes.
     5 *)
     6 
     7 signature DATATYPE_CODEGEN =
     8 sig
     9 end;
    10 
    11 structure Datatype_Codegen : DATATYPE_CODEGEN =
    12 struct
    13 
    14 fun add_code_for_datatype fcT_name thy =
    15   let
    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;
    19 
    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;
    23   in
    24     Ctr_Sugar_Code.add_ctr_code fcT_name As ctrs inject_thms distinct_thms case_thms thy
    25   end;
    26 
    27 val _ = Theory.setup (Datatype_Data.interpretation (K (fold add_code_for_datatype)));
    28 
    29 end;