src/Pure/Isar/class_declaration.ML
changeset 57181 2d13bf9ea77b
parent 56921 5bf71b4da706
child 57182 79d43c510b84
equal deleted inserted replaced
57180:74c81a5b5a34 57181:2d13bf9ea77b
     4 Declaring classes and subclass relations.
     4 Declaring classes and subclass relations.
     5 *)
     5 *)
     6 
     6 
     7 signature CLASS_DECLARATION =
     7 signature CLASS_DECLARATION =
     8 sig
     8 sig
     9   val class: (local_theory -> local_theory) -> binding -> class list ->
     9   val class: binding -> class list ->
    10     Element.context_i list -> theory -> string * local_theory
    10     Element.context_i list -> theory -> string * local_theory
    11   val class_cmd: (local_theory -> local_theory) -> binding -> xstring list ->
    11   val class_cmd: binding -> xstring list ->
    12     Element.context list -> theory -> string * local_theory
    12     Element.context list -> theory -> string * local_theory
    13   val prove_subclass: (local_theory -> local_theory) -> tactic -> class ->
    13   val prove_subclass: tactic -> class ->
    14     local_theory -> local_theory
    14     local_theory -> local_theory
    15   val subclass: (local_theory -> local_theory) -> class -> local_theory -> Proof.state
    15   val subclass: class -> local_theory -> Proof.state
    16   val subclass_cmd: (local_theory -> local_theory) -> xstring -> local_theory -> Proof.state
    16   val subclass_cmd: xstring -> local_theory -> Proof.state
    17 end;
    17 end;
    18 
    18 
    19 structure Class_Declaration: CLASS_DECLARATION =
    19 structure Class_Declaration: CLASS_DECLARATION =
    20 struct
    20 struct
    21 
    21 
   304     #> `get_axiom
   304     #> `get_axiom
   305     #-> (fn assm_axiom => fold (Sign.add_const_constraint o apsnd SOME o snd) params
   305     #-> (fn assm_axiom => fold (Sign.add_const_constraint o apsnd SOME o snd) params
   306     #> pair (param_map, params, assm_axiom)))
   306     #> pair (param_map, params, assm_axiom)))
   307   end;
   307   end;
   308 
   308 
   309 fun gen_class prep_class_spec before_exit b raw_supclasses raw_elems thy =
   309 fun gen_class prep_class_spec b raw_supclasses raw_elems thy =
   310   let
   310   let
   311     val class = Sign.full_name thy b;
   311     val class = Sign.full_name thy b;
   312     val prefix = Binding.qualify true "class";
   312     val prefix = Binding.qualify true "class";
   313     val (((sups, supparam_names), (supsort, base_sort, supexpr)), (elems, global_syntax)) =
   313     val (((sups, supparam_names), (supsort, base_sort, supexpr)), (elems, global_syntax)) =
   314       prep_class_spec thy raw_supclasses raw_elems;
   314       prep_class_spec thy raw_supclasses raw_elems;
   315   in
   315   in
   316     thy
   316     thy
   317     |> Expression.add_locale I b (prefix b) supexpr elems
   317     |> Expression.add_locale b (prefix b) supexpr elems
   318     |> snd |> Local_Theory.exit_global
   318     |> snd |> Local_Theory.exit_global
   319     |> adjungate_axclass b class base_sort sups supsort supparam_names global_syntax
   319     |> adjungate_axclass b class base_sort sups supsort supparam_names global_syntax
   320     |-> (fn (param_map, params, assm_axiom) =>
   320     |-> (fn (param_map, params, assm_axiom) =>
   321        `(fn thy => calculate thy class sups base_sort param_map assm_axiom)
   321        `(fn thy => calculate thy class sups base_sort param_map assm_axiom)
   322     #-> (fn (base_morph, eq_morph, export_morph, some_axiom, some_assm_intro, of_class) =>
   322     #-> (fn (base_morph, eq_morph, export_morph, some_axiom, some_assm_intro, of_class) =>
   323        Context.theory_map (Locale.add_registration (class, base_morph)
   323        Context.theory_map (Locale.add_registration (class, base_morph)
   324          (Option.map (rpair true) eq_morph) export_morph)
   324          (Option.map (rpair true) eq_morph) export_morph)
   325     #> Class.register class sups params base_sort base_morph export_morph some_axiom some_assm_intro of_class
   325     #> Class.register class sups params base_sort base_morph export_morph some_axiom some_assm_intro of_class
   326     #> Global_Theory.store_thm (prefix (Binding.qualified_name (class ^ ".of_class.intro")), of_class)))
   326     #> Global_Theory.store_thm (prefix (Binding.qualified_name (class ^ ".of_class.intro")), of_class)))
   327     |> snd
   327     |> snd
   328     |> Named_Target.init before_exit class
   328     |> Named_Target.init class
   329     |> pair class
   329     |> pair class
   330   end;
   330   end;
   331 
   331 
   332 in
   332 in
   333 
   333 
   340 
   340 
   341 (** subclass relations **)
   341 (** subclass relations **)
   342 
   342 
   343 local
   343 local
   344 
   344 
   345 fun gen_subclass prep_class do_proof before_exit raw_sup lthy =
   345 fun gen_subclass prep_class do_proof raw_sup lthy =
   346   let
   346   let
   347     val thy = Proof_Context.theory_of lthy;
   347     val thy = Proof_Context.theory_of lthy;
   348     val proto_sup = prep_class thy raw_sup;
   348     val proto_sup = prep_class thy raw_sup;
   349     val proto_sub =
   349     val proto_sub =
   350       (case Named_Target.peek lthy of
   350       (case Named_Target.peek lthy of
   369   after_qed (Option.map
   369   after_qed (Option.map
   370     (fn prop => Element.prove_witness ctxt prop tac) some_prop) ctxt;
   370     (fn prop => Element.prove_witness ctxt prop tac) some_prop) ctxt;
   371 
   371 
   372 in
   372 in
   373 
   373 
   374 fun prove_subclass before_exit tac = gen_subclass (K I) (tactic_proof tac) before_exit;
   374 fun prove_subclass tac = gen_subclass (K I) (tactic_proof tac);
   375 
   375 
   376 fun subclass x = gen_subclass (K I) user_proof x;
   376 fun subclass x = gen_subclass (K I) user_proof x;
   377 fun subclass_cmd x =
   377 fun subclass_cmd x =
   378   gen_subclass (Proof_Context.read_class o Proof_Context.init_global) user_proof x;
   378   gen_subclass (Proof_Context.read_class o Proof_Context.init_global) user_proof x;
   379 
   379