src/HOL/Tools/Ctr_Sugar/ctr_sugar.ML
changeset 58177 166131276380
parent 58176 710710a66173
child 58182 82478e6c60cb
equal deleted inserted replaced
58176:710710a66173 58177:166131276380
    41   val ctr_sugar_of_global: theory -> string -> ctr_sugar option
    41   val ctr_sugar_of_global: theory -> string -> ctr_sugar option
    42   val ctr_sugars_of: Proof.context -> ctr_sugar list
    42   val ctr_sugars_of: Proof.context -> ctr_sugar list
    43   val ctr_sugars_of_global: theory -> ctr_sugar list
    43   val ctr_sugars_of_global: theory -> ctr_sugar list
    44   val ctr_sugar_of_case: Proof.context -> string -> ctr_sugar option
    44   val ctr_sugar_of_case: Proof.context -> string -> ctr_sugar option
    45   val ctr_sugar_of_case_global: theory -> string -> ctr_sugar option
    45   val ctr_sugar_of_case_global: theory -> string -> ctr_sugar option
    46   val ctr_sugar_interpretation: (ctr_sugar -> theory -> theory) -> theory -> theory
    46   val ctr_sugar_interpretation: (ctr_sugar -> theory -> theory) ->
       
    47     (ctr_sugar -> local_theory -> local_theory) -> theory -> theory
    47   val register_ctr_sugar: string -> ctr_sugar -> local_theory -> local_theory
    48   val register_ctr_sugar: string -> ctr_sugar -> local_theory -> local_theory
    48   val default_register_ctr_sugar_global: string -> ctr_sugar -> theory -> theory
    49   val default_register_ctr_sugar_global: string -> ctr_sugar -> theory -> theory
    49 
    50 
    50   val mk_half_pairss: 'a list * 'a list -> ('a * 'a) list list
    51   val mk_half_pairss: 'a list * 'a list -> ('a * 'a) list list
    51   val join_halves: int -> 'a list list -> 'a list list -> 'a list * 'a list list list
    52   val join_halves: int -> 'a list list -> 'a list list -> 'a list * 'a list list list
   168 val ctr_sugars_of_global = ctr_sugars_of_generic o Context.Theory;
   169 val ctr_sugars_of_global = ctr_sugars_of_generic o Context.Theory;
   169 
   170 
   170 val ctr_sugar_of_case = ctr_sugar_of_case_generic o Context.Proof;
   171 val ctr_sugar_of_case = ctr_sugar_of_case_generic o Context.Proof;
   171 val ctr_sugar_of_case_global = ctr_sugar_of_case_generic o Context.Theory;
   172 val ctr_sugar_of_case_global = ctr_sugar_of_case_generic o Context.Theory;
   172 
   173 
   173 structure Ctr_Sugar_Interpretation = Interpretation
   174 structure Ctr_Sugar_Interpretation = Local_Interpretation
   174 (
   175 (
   175   type T = ctr_sugar;
   176   type T = ctr_sugar;
   176   val eq: T * T -> bool = op = o pairself #ctrs;
   177   val eq: T * T -> bool = op = o pairself #ctrs;
   177 );
   178 );
   178 
   179 
   179 fun with_repaired_path f (ctr_sugar as {ctrs = ctr1 :: _, ...} : ctr_sugar) thy =
   180 fun with_repaired_path g (ctr_sugar as {ctrs = ctr1 :: _, ...} : ctr_sugar) thy =
   180   thy
   181   thy
   181   |> Sign.root_path
   182   |> Sign.root_path
   182   |> Sign.add_path (Long_Name.qualifier (fst (dest_Type (body_type (fastype_of ctr1)))))
   183   |> Sign.add_path (Long_Name.qualifier (fst (dest_Type (body_type (fastype_of ctr1)))))
   183   |> (fn thy => f (transfer_ctr_sugar thy ctr_sugar) thy)
   184   |> (fn thy => g (transfer_ctr_sugar thy ctr_sugar) thy)
   184   |> Sign.restore_naming thy;
   185   |> Sign.restore_naming thy;
   185 
   186 
   186 fun ctr_sugar_interpretation f = Ctr_Sugar_Interpretation.interpretation (with_repaired_path f);
   187 val ctr_sugar_interpretation = Ctr_Sugar_Interpretation.interpretation o with_repaired_path;
   187 
   188 
   188 fun register_ctr_sugar key ctr_sugar =
   189 fun register_ctr_sugar key ctr_sugar =
   189   Local_Theory.declaration {syntax = false, pervasive = true}
   190   Local_Theory.declaration {syntax = false, pervasive = true}
   190     (fn phi => Data.map (Symtab.update (key, morph_ctr_sugar phi ctr_sugar)))
   191     (fn phi => Data.map (Symtab.update (key, morph_ctr_sugar phi ctr_sugar)))
   191   #> Local_Theory.background_theory
   192   #> Ctr_Sugar_Interpretation.data ctr_sugar;
   192     (fn thy => Ctr_Sugar_Interpretation.data (the (ctr_sugar_of_global thy key)) thy);
       
   193 
   193 
   194 fun default_register_ctr_sugar_global key ctr_sugar thy =
   194 fun default_register_ctr_sugar_global key ctr_sugar thy =
   195   let val tab = Data.get (Context.Theory thy) in
   195   let val tab = Data.get (Context.Theory thy) in
   196     if Symtab.defined tab key then
   196     if Symtab.defined tab key then
   197       thy
   197       thy
   198     else
   198     else
   199       thy
   199       thy
   200       |> Context.theory_map (Data.put (Symtab.update_new (key, ctr_sugar) tab))
   200       |> Context.theory_map (Data.put (Symtab.update_new (key, ctr_sugar) tab))
   201       |> Ctr_Sugar_Interpretation.data ctr_sugar
   201       |> Ctr_Sugar_Interpretation.data_global ctr_sugar
   202   end;
   202   end;
   203 
   203 
   204 val isN = "is_";
   204 val isN = "is_";
   205 val unN = "un_";
   205 val unN = "un_";
   206 val notN = "not_";
   206 val notN = "not_";