24592
|
1 |
(* Title: Pure/Isar/instance.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Florian Haftmann, TU Muenchen
|
|
4 |
|
25462
|
5 |
A primitive instance command, based on instantiation target.
|
24592
|
6 |
*)
|
|
7 |
|
|
8 |
signature INSTANCE =
|
|
9 |
sig
|
25462
|
10 |
val instantiate: arity list -> (local_theory -> local_theory)
|
|
11 |
-> (Proof.context -> tactic) -> theory -> theory
|
|
12 |
val instance: arity list -> ((bstring * Attrib.src list) * term) list
|
|
13 |
-> (thm list -> theory -> theory)
|
|
14 |
-> theory -> Proof.state
|
|
15 |
val prove_instance: tactic -> arity list -> ((bstring * Attrib.src list) * term) list
|
|
16 |
-> theory -> thm list * theory
|
|
17 |
|
|
18 |
val instantiation_cmd: (xstring * sort * xstring) list
|
24592
|
19 |
-> theory -> local_theory
|
25462
|
20 |
val instance_cmd: (xstring * sort * xstring) list -> ((bstring * Attrib.src list) * xstring) list
|
|
21 |
-> (thm list -> theory -> theory)
|
|
22 |
-> theory -> Proof.state
|
24592
|
23 |
end;
|
|
24 |
|
|
25 |
structure Instance : INSTANCE =
|
|
26 |
struct
|
|
27 |
|
25462
|
28 |
fun instantiation_cmd raw_arities thy =
|
|
29 |
TheoryTarget.instantiation (map (Sign.read_arity thy) raw_arities) thy;
|
|
30 |
|
|
31 |
fun instantiate arities f tac =
|
|
32 |
TheoryTarget.instantiation arities
|
|
33 |
#> f
|
|
34 |
#> Class.prove_instantiation tac
|
|
35 |
#> LocalTheory.exit
|
|
36 |
#> ProofContext.theory_of;
|
24592
|
37 |
|
25462
|
38 |
fun gen_instance prep_arity prep_attr prep_term do_proof raw_arities defs after_qed thy =
|
24592
|
39 |
let
|
25462
|
40 |
fun export_defs ctxt =
|
|
41 |
let
|
|
42 |
val ctxt_thy = ProofContext.init (ProofContext.theory_of ctxt);
|
|
43 |
in
|
|
44 |
map (snd o snd)
|
|
45 |
#> map (Assumption.export false ctxt ctxt_thy)
|
|
46 |
#> Variable.export ctxt ctxt_thy
|
|
47 |
end;
|
|
48 |
fun mk_def ctxt ((name, raw_attr), raw_t) =
|
24592
|
49 |
let
|
25462
|
50 |
val attr = map (prep_attr thy) raw_attr;
|
|
51 |
val t = prep_term ctxt raw_t;
|
|
52 |
in (NONE, ((name, attr), t)) end;
|
|
53 |
val arities = map (prep_arity thy) raw_arities;
|
|
54 |
in
|
|
55 |
thy
|
|
56 |
|> TheoryTarget.instantiation arities
|
|
57 |
|> `(fn ctxt => map (mk_def ctxt) defs)
|
|
58 |
|-> (fn defs => fold_map Specification.definition defs)
|
|
59 |
|-> (fn defs => `(fn ctxt => export_defs ctxt defs))
|
|
60 |
||> LocalTheory.exit
|
|
61 |
||> ProofContext.theory_of
|
|
62 |
||> TheoryTarget.instantiation arities
|
|
63 |
|-> (fn defs => do_proof defs (LocalTheory.theory (after_qed defs)))
|
|
64 |
end;
|
24592
|
65 |
|
25462
|
66 |
val instance = gen_instance Sign.cert_arity (K I) (K I)
|
|
67 |
(fn _ => fn after_qed => Class.proof_instantiation (after_qed #> Class.conclude_instantiation));
|
|
68 |
val instance_cmd = gen_instance Sign.read_arity Attrib.intern_src
|
|
69 |
(fn ctxt => Syntax.parse_prop ctxt #> Syntax.check_prop ctxt)
|
|
70 |
(fn _ => fn after_qed => Class.proof_instantiation (after_qed #> Class.conclude_instantiation));
|
|
71 |
fun prove_instance tac arities defs = gen_instance Sign.cert_arity (K I) (K I)
|
|
72 |
(fn defs => fn after_qed => Class.prove_instantiation (K tac)
|
|
73 |
#> after_qed #> Class.conclude_instantiation #> ProofContext.theory_of #> pair defs) arities defs (K I);
|
24592
|
74 |
|
|
75 |
end;
|