src/Pure/Isar/instance.ML
changeset 25502 9200b36280c0
parent 25485 33840a854e63
child 25514 4b508bb31a6c
equal deleted inserted replaced
25501:845883bd3a6b 25502:9200b36280c0
     8 signature INSTANCE =
     8 signature INSTANCE =
     9 sig
     9 sig
    10   val instantiate: arity list -> (local_theory -> local_theory)
    10   val instantiate: arity list -> (local_theory -> local_theory)
    11     -> (Proof.context -> tactic) -> theory -> theory
    11     -> (Proof.context -> tactic) -> theory -> theory
    12   val instance: arity list -> ((bstring * Attrib.src list) * term) list
    12   val instance: arity list -> ((bstring * Attrib.src list) * term) list
    13     -> (thm list -> theory -> theory)
       
    14     -> theory -> Proof.state
    13     -> theory -> Proof.state
    15   val prove_instance: tactic -> arity list -> ((bstring * Attrib.src list) * term) list
    14   val prove_instance: tactic -> arity list -> ((bstring * Attrib.src list) * term) list
    16     -> theory -> thm list * theory
    15     -> theory -> thm list * theory
    17 
    16 
    18   val instantiation_cmd: (xstring * sort * xstring) list
    17   val instantiation_cmd: (xstring * sort * xstring) list
    19     -> theory -> local_theory
    18     -> theory -> local_theory
    20   val instance_cmd: (xstring * sort * xstring) list -> ((bstring * Attrib.src list) * xstring) list
    19   val instance_cmd: (xstring * sort * xstring) list -> ((bstring * Attrib.src list) * xstring) list
    21     -> (thm list -> theory -> theory)
       
    22     -> theory -> Proof.state
    20     -> theory -> Proof.state
    23 end;
    21 end;
    24 
    22 
    25 structure Instance : INSTANCE =
    23 structure Instance : INSTANCE =
    26 struct
    24 struct
    33   #> f
    31   #> f
    34   #> Class.prove_instantiation_instance tac
    32   #> Class.prove_instantiation_instance tac
    35   #> LocalTheory.exit
    33   #> LocalTheory.exit
    36   #> ProofContext.theory_of;
    34   #> ProofContext.theory_of;
    37 
    35 
    38 fun gen_instance prep_arity prep_attr parse_term do_proof raw_arities defs after_qed thy =
    36 fun gen_instance prep_arity prep_attr parse_term do_proof do_proof' raw_arities defs thy =
    39   let
    37   let
       
    38     val arities = map (prep_arity thy) raw_arities;
    40     fun export_defs ctxt = 
    39     fun export_defs ctxt = 
    41       let
    40       let
    42         val ctxt_thy = ProofContext.init (ProofContext.theory_of ctxt);
    41         val ctxt_thy = ProofContext.init (ProofContext.theory_of ctxt);
    43       in
    42       in
    44         map (snd o snd)
    43         map (snd o snd)
    52       in (NONE, ((name, attr), t)) end;
    51       in (NONE, ((name, attr), t)) end;
    53     fun define def ctxt =
    52     fun define def ctxt =
    54       let
    53       let
    55         val def' = (apsnd o apsnd) (Syntax.check_prop ctxt) def;
    54         val def' = (apsnd o apsnd) (Syntax.check_prop ctxt) def;
    56       in Specification.definition def' ctxt end;
    55       in Specification.definition def' ctxt end;
    57     val arities = map (prep_arity thy) raw_arities;
    56   in if not (null defs) orelse forall (fn (_, _, sort) =>
    58   in
    57       forall (Class.is_class thy) sort) arities
       
    58   then
    59     thy
    59     thy
    60     |> TheoryTarget.instantiation arities
    60     |> TheoryTarget.instantiation arities
    61     |> `(fn ctxt => map (mk_def ctxt) defs)
    61     |> `(fn ctxt => map (mk_def ctxt) defs)
    62     |-> (fn defs => fold_map Specification.definition defs)
    62     |-> (fn defs => fold_map Specification.definition defs)
    63     |-> (fn defs => `(fn ctxt => export_defs ctxt defs))
    63     |-> (fn defs => `(fn ctxt => export_defs ctxt defs))
    64     ||> LocalTheory.exit
    64     ||> LocalTheory.exit
    65     ||> ProofContext.theory_of
    65     ||> ProofContext.theory_of
    66     ||> TheoryTarget.instantiation arities
    66     ||> TheoryTarget.instantiation arities
    67     |-> (fn defs => do_proof defs (LocalTheory.theory (after_qed defs)))
    67     |-> (fn defs => do_proof defs)
       
    68   else
       
    69     thy
       
    70     |> do_proof' arities
    68   end;
    71   end;
    69 
    72 
    70 val instance = gen_instance Sign.cert_arity (K I) (K I)
    73 val instance = gen_instance Sign.cert_arity (K I) (K I)
    71   (fn _ => fn after_qed => Class.instantiation_instance (after_qed #> Class.conclude_instantiation));
    74   (fn _ => Class.instantiation_instance Class.conclude_instantiation) (Class.instance_arity I);
    72 val instance_cmd = gen_instance Sign.read_arity Attrib.intern_src Syntax.parse_prop
    75 val instance_cmd = gen_instance Sign.read_arity Attrib.intern_src Syntax.parse_prop
    73   (fn _ => fn after_qed => Class.instantiation_instance (after_qed #> Class.conclude_instantiation));
    76   (fn _ => Class.instantiation_instance Class.conclude_instantiation) (Class.instance_arity I);
    74 fun prove_instance tac arities defs = gen_instance Sign.cert_arity (K I) (K I)
    77 fun prove_instance tac arities defs = gen_instance Sign.cert_arity (K I) (K I)
    75   (fn defs => fn after_qed => Class.prove_instantiation_instance (K tac)
    78   (fn defs => Class.prove_instantiation_instance (K tac)
    76     #> after_qed #> Class.conclude_instantiation #> ProofContext.theory_of #> pair defs) arities defs (K I);
    79     #> Class.conclude_instantiation #> ProofContext.theory_of #> pair defs)
       
    80    (pair [] o ProofContext.theory_of o Proof.global_terminal_proof
       
    81       (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE)
       
    82       oo Class.instance_arity I) arities defs;
    77 
    83 
    78 end;
    84 end;