src/Pure/Tools/class_package.ML
changeset 20368 2461a0485623
parent 20353 d73e49780ef2
child 20385 2f52b5aba086
equal deleted inserted replaced
20367:ba1c262c7625 20368:2461a0485623
   280 (* axclass instances *)
   280 (* axclass instances *)
   281 
   281 
   282 local
   282 local
   283 
   283 
   284 fun gen_instance mk_prop add_thm after_qed insts thy =
   284 fun gen_instance mk_prop add_thm after_qed insts thy =
   285   thy
   285   let
   286   |> ProofContext.init
   286     fun after_qed' results =
   287   |> Proof.theorem_i PureThy.internalK NONE (after_qed oo (fold o fold) add_thm) NONE ("", [])
   287       ProofContext.theory ((fold o fold) add_thm results #> after_qed);
   288        ((map (fn t => (("", []), [(t, [])])) o maps (mk_prop thy)) insts);
   288   in
       
   289     thy
       
   290     |> ProofContext.init
       
   291     |> Proof.theorem_i PureThy.internalK NONE after_qed' NONE ("", [])
       
   292       ((map (fn t => (("", []), [(t, [])])) o maps (mk_prop thy)) insts)
       
   293   end;
   289 
   294 
   290 in
   295 in
   291 
   296 
   292 val axclass_instance_arity =
   297 val axclass_instance_arity =
   293   gen_instance (Logic.mk_arities oo Sign.read_arity) AxClass.add_arity;
   298   gen_instance (Logic.mk_arities oo Sign.read_arity) AxClass.add_arity;
   308     val (c, thy') = thy
   313     val (c, thy') = thy
   309       |> AxClass.define_class_i (name, supsort) params axs;
   314       |> AxClass.define_class_i (name, supsort) params axs;
   310     val {intro, axioms, ...} = AxClass.get_definition thy' c;
   315     val {intro, axioms, ...} = AxClass.get_definition thy' c;
   311   in ((c, (intro, axioms)), thy') end;
   316   in ((c, (intro, axioms)), thy') end;
   312 
   317 
       
   318 (* FIXME proper locale interface *)
   313 fun prove_interpretation_i (prfx, atts) expr insts tac thy =
   319 fun prove_interpretation_i (prfx, atts) expr insts tac thy =
   314   let
   320   let
   315     fun ad_hoc_term NONE = NONE
   321     fun ad_hoc_term (Const (c, ty)) =
   316       | ad_hoc_term (SOME (Const (c, ty))) =
       
   317           let
   322           let
   318             val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_typ thy))) ty;
   323             val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_typ thy))) ty;
   319             val s = c ^ "::" ^ Pretty.output p;
   324             val s = c ^ "::" ^ Pretty.output p;
   320           in SOME s end
   325           in s end
   321       | ad_hoc_term (SOME t) =
   326       | ad_hoc_term t =
   322           let
   327           let
   323             val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_term thy))) t;
   328             val p = setmp show_types true (setmp show_sorts true (setmp print_mode [] (Sign.pretty_term thy))) t;
   324             val s = Pretty.output p;
   329             val s = Pretty.output p;
   325           in SOME s end;
   330           in s end;
   326   in
   331   in
   327     thy
   332     thy
   328     |> Locale.interpretation (prfx, atts) expr (map ad_hoc_term insts)
   333     |> Locale.interpretation I (prfx, atts) expr (map (Option.map ad_hoc_term) insts)
   329     |> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE)
   334     |> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE)
   330     |-> (fn _ => I)
   335     |> ProofContext.theory_of
   331   end;
   336   end;
   332 
   337 
   333 fun gen_class add_locale prep_class bname raw_supclasses raw_elems thy =
   338 fun gen_class add_locale prep_class bname raw_supclasses raw_elems thy =
   334   let
   339   let
   335     val supclasses = map (prep_class thy) raw_supclasses;
   340     val supclasses = map (prep_class thy) raw_supclasses;
   538 
   543 
   539 end; (* local *)
   544 end; (* local *)
   540 
   545 
   541 local
   546 local
   542 
   547 
   543 fun add_interpretation_in (after_qed : theory -> theory) (name, expr) thy =
   548 (* FIXME proper locale interface *)
       
   549 fun prove_interpretation_in tac after_qed (name, expr) thy =
   544   thy
   550   thy
   545   |> Locale.interpretation_in_locale (name, expr);
   551   |> Locale.interpretation_in_locale (ProofContext.theory after_qed) (name, expr)
   546 
       
   547 fun prove_interpretation_in tac (after_qed : theory -> theory) (name, expr) thy =
       
   548   thy
       
   549   |> Locale.interpretation_in_locale (name, expr)
       
   550   |> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE)
   552   |> Proof.global_terminal_proof (Method.Basic (fn _ => Method.SIMPLE_METHOD tac), NONE)
   551   |> snd
   553   |> ProofContext.theory_of;
   552   |> after_qed;
       
   553 
   554 
   554 fun gen_instance_sort prep_class prep_sort do_proof (raw_class, raw_sort) theory =
   555 fun gen_instance_sort prep_class prep_sort do_proof (raw_class, raw_sort) theory =
   555   let
   556   let
   556     val class = prep_class theory raw_class;
   557     val class = prep_class theory raw_class;
   557     val sort = prep_sort theory raw_sort;
   558     val sort = prep_sort theory raw_sort;
   581     |> do_proof after_qed (loc_name, loc_expr)
   582     |> do_proof after_qed (loc_name, loc_expr)
   582   end;
   583   end;
   583 
   584 
   584 fun instance_sort' do_proof = gen_instance_sort intern_class read_sort do_proof;
   585 fun instance_sort' do_proof = gen_instance_sort intern_class read_sort do_proof;
   585 fun instance_sort_i' do_proof = gen_instance_sort certify_class certify_sort do_proof;
   586 fun instance_sort_i' do_proof = gen_instance_sort certify_class certify_sort do_proof;
   586 val setup_proof = add_interpretation_in;
   587 val setup_proof = Locale.interpretation_in_locale o ProofContext.theory;
   587 val tactic_proof = prove_interpretation_in;
   588 val tactic_proof = prove_interpretation_in;
   588 
   589 
   589 in
   590 in
   590 
   591 
   591 val instance_sort = instance_sort' setup_proof;
   592 val instance_sort = instance_sort' setup_proof;