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
|
25536
|
10 |
val instantiation_cmd: xstring list * sort * xstring -> theory -> local_theory
|
|
11 |
val instance_cmd: xstring * sort * xstring -> ((bstring * Attrib.src list) * xstring) list
|
25462
|
12 |
-> theory -> Proof.state
|
24592
|
13 |
end;
|
|
14 |
|
|
15 |
structure Instance : INSTANCE =
|
|
16 |
struct
|
|
17 |
|
25864
|
18 |
fun read_single_arity thy (raw_tyco, raw_sorts, raw_sort) =
|
|
19 |
let
|
|
20 |
val (tyco, sorts, sort) = Sign.read_arity thy (raw_tyco, raw_sorts, raw_sort);
|
|
21 |
val vs = Name.names Name.context Name.aT sorts;
|
|
22 |
in (tyco, vs, sort) end;
|
|
23 |
|
25536
|
24 |
fun read_multi_arity thy (raw_tycos, raw_sorts, raw_sort) =
|
|
25 |
let
|
|
26 |
val all_arities = map (fn raw_tyco => Sign.read_arity thy
|
|
27 |
(raw_tyco, raw_sorts, raw_sort)) raw_tycos;
|
|
28 |
val tycos = map #1 all_arities;
|
|
29 |
val (_, sorts, sort) = hd all_arities;
|
25864
|
30 |
val vs = Name.names Name.context Name.aT sorts;
|
|
31 |
in (tycos, vs, sort) end;
|
25536
|
32 |
|
25462
|
33 |
fun instantiation_cmd raw_arities thy =
|
25536
|
34 |
TheoryTarget.instantiation (read_multi_arity thy raw_arities) thy;
|
25462
|
35 |
|
25864
|
36 |
fun instance_cmd raw_arities defs thy =
|
24592
|
37 |
let
|
25864
|
38 |
val (tyco, vs, sort) = read_single_arity thy raw_arities;
|
25462
|
39 |
fun mk_def ctxt ((name, raw_attr), raw_t) =
|
24592
|
40 |
let
|
25864
|
41 |
val attr = map (Attrib.intern_src thy) raw_attr;
|
|
42 |
val t = Syntax.parse_prop ctxt raw_t;
|
25462
|
43 |
in (NONE, ((name, attr), t)) end;
|
25485
|
44 |
fun define def ctxt =
|
|
45 |
let
|
|
46 |
val def' = (apsnd o apsnd) (Syntax.check_prop ctxt) def;
|
|
47 |
in Specification.definition def' ctxt end;
|
25569
|
48 |
val _ = if not (null defs) then Output.legacy_feature
|
25829
|
49 |
"Instance command with attached definitions; use instantiation instead." else ();
|
25536
|
50 |
in if not (null defs) orelse forall (Class.is_class thy) sort
|
25502
|
51 |
then
|
25462
|
52 |
thy
|
25864
|
53 |
|> TheoryTarget.instantiation ([tyco], vs, sort)
|
25462
|
54 |
|> `(fn ctxt => map (mk_def ctxt) defs)
|
|
55 |
|-> (fn defs => fold_map Specification.definition defs)
|
25864
|
56 |
|> snd
|
|
57 |
|> LocalTheory.reinit
|
|
58 |
|> Class.instantiation_instance Class.conclude_instantiation
|
25502
|
59 |
else
|
|
60 |
thy
|
25864
|
61 |
|> Class.instance_arity I (tyco, map snd vs, sort)
|
25462
|
62 |
end;
|
24592
|
63 |
|
|
64 |
end;
|