src/HOL/Tools/Datatype/datatype_data.ML
changeset 43580 023a1d1f97bd
parent 43329 84472e198515
child 43581 c3e4d280bdeb
equal deleted inserted replaced
43579:66f8cf4f82d9 43580:023a1d1f97bd
    21   val the_spec : theory -> string -> (string * sort) list * (string * typ list) list
    21   val the_spec : theory -> string -> (string * sort) list * (string * typ list) list
    22   val all_distincts : theory -> typ list -> thm list list
    22   val all_distincts : theory -> typ list -> thm list list
    23   val get_constrs : theory -> string -> (string * typ) list option
    23   val get_constrs : theory -> string -> (string * typ) list option
    24   val get_all : theory -> info Symtab.table
    24   val get_all : theory -> info Symtab.table
    25   val info_of_constr : theory -> string * typ -> info option
    25   val info_of_constr : theory -> string * typ -> info option
       
    26   val info_of_constr_permissive : theory -> string * typ -> info option
    26   val info_of_case : theory -> string -> info option
    27   val info_of_case : theory -> string -> info option
    27   val interpretation : (config -> string list -> theory -> theory) -> theory -> theory
    28   val interpretation : (config -> string list -> theory -> theory) -> theory -> theory
    28   val make_case :  Proof.context -> Datatype_Case.config -> string list -> term ->
    29   val make_case :  Proof.context -> Datatype_Case.config -> string list -> term ->
    29     (term * term) list -> term
    30     (term * term) list -> term
    30   val strip_case : Proof.context -> bool -> term -> (term * (term * term) list) option
    31   val strip_case : Proof.context -> bool -> term -> (term * (term * term) list) option
    66   (case get_info thy name of
    67   (case get_info thy name of
    67     SOME info => info
    68     SOME info => info
    68   | NONE => error ("Unknown datatype " ^ quote name));
    69   | NONE => error ("Unknown datatype " ^ quote name));
    69 
    70 
    70 fun info_of_constr thy (c, T) =
    71 fun info_of_constr thy (c, T) =
       
    72   let
       
    73     val tab = Symtab.lookup_list ((#constrs o DatatypesData.get) thy) c;
       
    74   in
       
    75     case body_type T of
       
    76       Type (tyco, _) => AList.lookup (op =) tab tyco
       
    77     | _ => NONE
       
    78   end;
       
    79 
       
    80 fun info_of_constr_permissive thy (c, T) =
    71   let
    81   let
    72     val tab = Symtab.lookup_list ((#constrs o DatatypesData.get) thy) c;
    82     val tab = Symtab.lookup_list ((#constrs o DatatypesData.get) thy) c;
    73     val hint = case body_type T of Type (tyco, _) => SOME tyco | _ => NONE;
    83     val hint = case body_type T of Type (tyco, _) => SOME tyco | _ => NONE;
    74     val default =
    84     val default =
    75       if null tab then NONE
    85       if null tab then NONE
   214 
   224 
   215 
   225 
   216 (* translation rules for case *)
   226 (* translation rules for case *)
   217 
   227 
   218 fun make_case ctxt = Datatype_Case.make_case
   228 fun make_case ctxt = Datatype_Case.make_case
   219   (info_of_constr (Proof_Context.theory_of ctxt)) ctxt;
   229   (info_of_constr_permissive (Proof_Context.theory_of ctxt)) ctxt;
   220 
   230 
   221 fun strip_case ctxt = Datatype_Case.strip_case
   231 fun strip_case ctxt = Datatype_Case.strip_case
   222   (info_of_case (Proof_Context.theory_of ctxt));
   232   (info_of_case (Proof_Context.theory_of ctxt));
   223 
   233 
   224 fun add_case_tr' case_names thy =
   234 fun add_case_tr' case_names thy =
   228       in (case_name', Datatype_Case.case_tr' info_of_case case_name')
   238       in (case_name', Datatype_Case.case_tr' info_of_case case_name')
   229       end) case_names, []) thy;
   239       end) case_names, []) thy;
   230 
   240 
   231 val trfun_setup =
   241 val trfun_setup =
   232   Sign.add_advanced_trfuns ([],
   242   Sign.add_advanced_trfuns ([],
   233     [(@{syntax_const "_case_syntax"}, Datatype_Case.case_tr true info_of_constr)],
   243     [(@{syntax_const "_case_syntax"}, Datatype_Case.case_tr true info_of_constr_permissive)],
   234     [], []);
   244     [], []);
   235 
   245 
   236 
   246 
   237 
   247 
   238 (** document antiquotation **)
   248 (** document antiquotation **)