src/Pure/Isar/class.ML
changeset 47078 6890c02c4c12
parent 47061 355317493f34
child 47079 6231adc3895d
equal deleted inserted replaced
47077:3031603233e3 47078:6890c02c4c12
   143 
   143 
   144 fun these_defs thy = maps (#defs o the_class_data thy) o ancestry thy;
   144 fun these_defs thy = maps (#defs o the_class_data thy) o ancestry thy;
   145 fun these_operations thy = maps (#operations o the_class_data thy) o ancestry thy;
   145 fun these_operations thy = maps (#operations o the_class_data thy) o ancestry thy;
   146 
   146 
   147 val base_morphism = #base_morph oo the_class_data;
   147 val base_morphism = #base_morph oo the_class_data;
       
   148 
   148 fun morphism thy class =
   149 fun morphism thy class =
   149   (case Element.eq_morphism thy (these_defs thy [class]) of
   150   (case Element.eq_morphism thy (these_defs thy [class]) of
   150     SOME eq_morph => base_morphism thy class $> eq_morph
   151     SOME eq_morph => base_morphism thy class $> eq_morph
   151   | NONE => base_morphism thy class);
   152   | NONE => base_morphism thy class);
       
   153 
   152 val export_morphism = #export_morph oo the_class_data;
   154 val export_morphism = #export_morph oo the_class_data;
   153 
   155 
   154 fun print_classes ctxt =
   156 fun print_classes ctxt =
   155   let
   157   let
   156     val thy = Proof_Context.theory_of ctxt;
   158     val thy = Proof_Context.theory_of ctxt;
   226 fun register_subclass (sub, sup) some_dep_morph some_wit export thy =
   228 fun register_subclass (sub, sup) some_dep_morph some_wit export thy =
   227   let
   229   let
   228     val intros = (snd o rules thy) sup :: map_filter I
   230     val intros = (snd o rules thy) sup :: map_filter I
   229       [Option.map (Drule.export_without_context_open o Element.conclude_witness) some_wit,
   231       [Option.map (Drule.export_without_context_open o Element.conclude_witness) some_wit,
   230         (fst o rules thy) sub];
   232         (fst o rules thy) sub];
   231     val tac = EVERY (map (TRYALL o Tactic.rtac) intros);
   233     val classrel =
   232     val classrel = Skip_Proof.prove_global thy [] [] (Logic.mk_classrel (sub, sup))
   234       Skip_Proof.prove_global thy [] [] (Logic.mk_classrel (sub, sup))
   233       (K tac);
   235         (K (EVERY (map (TRYALL o Tactic.rtac) intros)));
   234     val diff_sort = Sign.complete_sort thy [sup]
   236     val diff_sort = Sign.complete_sort thy [sup]
   235       |> subtract (op =) (Sign.complete_sort thy [sub])
   237       |> subtract (op =) (Sign.complete_sort thy [sub])
   236       |> filter (is_class thy);
   238       |> filter (is_class thy);
   237     val add_dependency =
   239     val add_dependency =
   238       (case some_dep_morph of
   240       (case some_dep_morph of
   310 
   312 
   311 (* class target *)
   313 (* class target *)
   312 
   314 
   313 val class_prefix = Logic.const_of_class o Long_Name.base_name;
   315 val class_prefix = Logic.const_of_class o Long_Name.base_name;
   314 
   316 
       
   317 local
       
   318 
   315 fun target_extension f class lthy =
   319 fun target_extension f class lthy =
   316   lthy
   320   lthy
   317   |> Local_Theory.raw_theory f
   321   |> Local_Theory.raw_theory f
   318   |> Local_Theory.target (synchronize_class_syntax [class]
   322   |> Local_Theory.target (synchronize_class_syntax [class]
   319       (base_sort (Proof_Context.theory_of lthy) class));
   323       (base_sort (Proof_Context.theory_of lthy) class));
   320 
       
   321 local
       
   322 
   324 
   323 fun target_const class ((c, mx), (type_params, dict)) thy =
   325 fun target_const class ((c, mx), (type_params, dict)) thy =
   324   let
   326   let
   325     val morph = morphism thy class;
   327     val morph = morphism thy class;
   326     val b = Morphism.binding morph c;
   328     val b = Morphism.binding morph c;
   476   in if Vartab.is_empty tvartab then ts else (map o map_types) inst ts end;
   478   in if Vartab.is_empty tvartab then ts else (map o map_types) inst ts end;
   477 
   479 
   478 
   480 
   479 (* target *)
   481 (* target *)
   480 
   482 
   481 fun define_overloaded (c, U) v (b_def, rhs) = Local_Theory.background_theory_result
   483 fun define_overloaded (c, U) v (b_def, rhs) =
   482     (AxClass.declare_overloaded (c, U) ##>> AxClass.define_overloaded b_def (c, rhs))
   484   Local_Theory.background_theory_result (AxClass.declare_overloaded (c, U)
       
   485   ##>> AxClass.define_overloaded b_def (c, rhs))
   483   ##> (map_instantiation o apsnd) (filter_out (fn (_, (v', _)) => v' = v))
   486   ##> (map_instantiation o apsnd) (filter_out (fn (_, (v', _)) => v' = v))
   484   ##> Local_Theory.target synchronize_inst_syntax;
   487   ##> Local_Theory.target synchronize_inst_syntax;
   485 
   488 
   486 fun foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   489 fun foundation (((b, U), mx), (b_def, rhs)) (type_params, term_params) lthy =
   487   (case instantiation_param lthy b of
   490   (case instantiation_param lthy b of
   601 fun instance_arity_cmd raw_arities thy =
   604 fun instance_arity_cmd raw_arities thy =
   602   let
   605   let
   603     val (tycos, vs, sort) = read_multi_arity thy raw_arities;
   606     val (tycos, vs, sort) = read_multi_arity thy raw_arities;
   604     val sorts = map snd vs;
   607     val sorts = map snd vs;
   605     val arities = maps (fn tyco => Logic.mk_arities (tyco, sorts, sort)) tycos;
   608     val arities = maps (fn tyco => Logic.mk_arities (tyco, sorts, sort)) tycos;
   606     fun after_qed results = Proof_Context.background_theory
   609     fun after_qed results =
   607       ((fold o fold) AxClass.add_arity results);
   610       Proof_Context.background_theory ((fold o fold) AxClass.add_arity results);
   608   in
   611   in
   609     thy
   612     thy
   610     |> Proof_Context.init_global
   613     |> Proof_Context.init_global
   611     |> Proof.theorem NONE after_qed (map (fn t => [(t, [])]) arities)
   614     |> Proof.theorem NONE after_qed (map (fn t => [(t, [])]) arities)
   612   end;
   615   end;