src/HOL/Tools/typedef.ML
changeset 58662 5963cdbad926
parent 58239 1c5bc387bd4c
child 58959 1f195ed99941
equal deleted inserted replaced
58661:2b9485a2d152 58662:5963cdbad926
    13     Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm,
    13     Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm,
    14     Rep_induct: thm, Abs_induct: thm}
    14     Rep_induct: thm, Abs_induct: thm}
    15   val transform_info: morphism -> info -> info
    15   val transform_info: morphism -> info -> info
    16   val get_info: Proof.context -> string -> info list
    16   val get_info: Proof.context -> string -> info list
    17   val get_info_global: theory -> string -> info list
    17   val get_info_global: theory -> string -> info list
    18   val interpretation: (string -> theory -> theory) -> theory -> theory
    18   val interpretation: (string -> local_theory -> local_theory) -> theory -> theory
    19   val add_typedef: bool -> binding * (string * sort) list * mixfix ->
    19   val add_typedef: bool -> binding * (string * sort) list * mixfix ->
    20     term -> (binding * binding) option -> tactic -> local_theory -> (string * info) * local_theory
    20     term -> (binding * binding) option -> tactic -> local_theory -> (string * info) * local_theory
    21   val add_typedef_global: bool -> binding * (string * sort) list * mixfix ->
    21   val add_typedef_global: bool -> binding * (string * sort) list * mixfix ->
    22     term -> (binding * binding) option -> tactic -> theory -> (string * info) * theory
    22     term -> (binding * binding) option -> tactic -> theory -> (string * info) * theory
    23   val typedef: (binding * (string * sort) list * mixfix) * term *
    23   val typedef: (binding * (string * sort) list * mixfix) * term *
    69 fun put_info name info = Data.map (Symtab.cons_list (name, info));
    69 fun put_info name info = Data.map (Symtab.cons_list (name, info));
    70 
    70 
    71 
    71 
    72 (* global interpretation *)
    72 (* global interpretation *)
    73 
    73 
    74 structure Typedef_Interpretation = Interpretation(type T = string val eq = op =);
    74 structure Typedef_Plugin = Plugin(type T = string);
    75 
    75 
    76 fun with_repaired_path f name thy =
    76 val typedef_plugin = Plugin_Name.declare_setup @{binding typedef};
    77   thy
    77 
    78   |> Sign.root_path
    78 fun interpretation f =
    79   |> Sign.add_path (Long_Name.qualifier name)
    79   Typedef_Plugin.interpretation typedef_plugin
    80   |> f name
    80     (fn name => fn lthy =>
    81   |> Sign.restore_naming thy;
    81       lthy
    82 
    82       |> Local_Theory.map_naming
    83 fun interpretation f = Typedef_Interpretation.interpretation (with_repaired_path f);
    83           (Name_Space.root_path #> Name_Space.add_path (Long_Name.qualifier name))
    84 
    84       |> f name
    85 val _ = Theory.setup Typedef_Interpretation.init;
    85       |> Local_Theory.restore_naming lthy);
    86 
    86 
    87 
    87 
    88 (* primitive typedef axiomatization -- for fresh typedecl *)
    88 (* primitive typedef axiomatization -- for fresh typedecl *)
    89 
    89 
    90 fun mk_inhabited A =
    90 fun mk_inhabited A =
   227           Abs_cases = Abs_cases, Rep_induct = Rep_induct, Abs_induct = Abs_induct});
   227           Abs_cases = Abs_cases, Rep_induct = Rep_induct, Abs_induct = Abs_induct});
   228       in
   228       in
   229         lthy2
   229         lthy2
   230         |> Local_Theory.declaration {syntax = false, pervasive = true}
   230         |> Local_Theory.declaration {syntax = false, pervasive = true}
   231           (fn phi => put_info full_name (transform_info phi info))
   231           (fn phi => put_info full_name (transform_info phi info))
   232         |> Local_Theory.background_theory (Typedef_Interpretation.data full_name)
   232         |> Typedef_Plugin.data Plugin_Name.default_filter full_name
   233         |> pair (full_name, info)
   233         |> pair (full_name, info)
   234       end;
   234       end;
   235 
   235 
   236   in ((goal, goal_pat, typedef_result), alias_lthy) end
   236   in ((goal, goal_pat, typedef_result), alias_lthy) end
   237   handle ERROR msg =>
   237   handle ERROR msg =>