src/HOL/Tools/typecopy_package.ML
changeset 26513 6f306c8c2c54
parent 26475 3cc1e48d0ce1
child 26732 6ea9de67e576
equal deleted inserted replaced
26512:682dfb674df3 26513:6f306c8c2c54
   123 fun add_typecopy_spec tyco thy =
   123 fun add_typecopy_spec tyco thy =
   124   let
   124   let
   125     val SOME { constr, proj_def, inject, vs, ... } = get_info thy tyco;
   125     val SOME { constr, proj_def, inject, vs, ... } = get_info thy tyco;
   126     val vs' = (map o apsnd) (curry (Sorts.inter_sort (Sign.classes_of thy)) [HOLogic.class_eq]) vs;
   126     val vs' = (map o apsnd) (curry (Sorts.inter_sort (Sign.classes_of thy)) [HOLogic.class_eq]) vs;
   127     val ty = Logic.unvarifyT (Sign.the_const_type thy constr);
   127     val ty = Logic.unvarifyT (Sign.the_const_type thy constr);
       
   128     fun add_def tyco lthy =
       
   129       let
       
   130         val ty = Type (tyco, map TFree vs');
       
   131         fun mk_side const_name = Const (const_name, ty --> ty --> HOLogic.boolT)
       
   132           $ Free ("x", ty) $ Free ("y", ty);
       
   133         val def = HOLogic.mk_Trueprop (HOLogic.mk_eq
       
   134           (mk_side @{const_name eq}, mk_side @{const_name "op ="}));
       
   135         val def' = Syntax.check_term lthy def;
       
   136         val ((_, (_, thm)), lthy') = Specification.definition
       
   137           (NONE, (("", []), def')) lthy;
       
   138         val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy);
       
   139         val thm' = singleton (ProofContext.export lthy' ctxt_thy) thm;
       
   140       in (thm', lthy') end;
       
   141     fun tac thms = Class.intro_classes_tac []
       
   142       THEN ALLGOALS (ProofContext.fact_tac thms);
       
   143     fun add_eq_thm thy = 
       
   144       let
       
   145         val eq = inject
       
   146           |> CodeUnit.constrain_thm [HOLogic.class_eq]
       
   147           |> Simpdata.mk_eq
       
   148           |> MetaSimplifier.rewrite_rule [Thm.transfer thy @{thm equals_eq}];
       
   149       in Code.add_func eq thy end;
   128   in
   150   in
   129     thy
   151     thy
   130     |> Code.add_datatype [(constr, ty)]
   152     |> Code.add_datatype [(constr, ty)]
   131     |> Code.add_func proj_def
   153     |> Code.add_func proj_def
   132     |> TheoryTarget.instantiation ([tyco], vs', [HOLogic.class_eq])
   154     |> TheoryTarget.instantiation ([tyco], vs', [HOLogic.class_eq])
   133     |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   155     |> add_def tyco
   134     |> LocalTheory.exit
   156     |-> (fn thm => Class.prove_instantiation_instance (K (tac [thm]))
   135     |> ProofContext.theory_of
   157     #> LocalTheory.exit
   136     |> Code.add_func (CodeUnit.constrain_thm [HOLogic.class_eq] inject)
   158     #> ProofContext.theory_of
       
   159     #> Code.del_func thm
       
   160     #> add_eq_thm)
   137   end;
   161   end;
   138 
   162 
   139 val setup =
   163 val setup =
   140   TypecopyInterpretation.init
   164   TypecopyInterpretation.init
   141   #> interpretation add_typecopy_spec
   165   #> interpretation add_typecopy_spec