author | wenzelm |
Fri, 15 Jul 2005 15:44:15 +0200 | |
changeset 16861 | 7446b4be013b |
parent 16850 | 35e07087aba2 |
child 16894 | 40f80823b451 |
permissions | -rw-r--r-- |
5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
5 |
The key concept of Isar proof contexts. |
5819 | 6 |
*) |
7 |
||
14707 | 8 |
val show_structs = ref false; |
9 |
||
5819 | 10 |
signature PROOF_CONTEXT = |
11 |
sig |
|
12 |
type context |
|
9470 | 13 |
type exporter |
5819 | 14 |
exception CONTEXT of string * context |
15 |
val theory_of: context -> theory |
|
16458 | 16 |
val sign_of: context -> theory (*obsolete*) |
14828 | 17 |
val is_fixed: context -> string -> bool |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
18 |
val is_known: context -> string -> bool |
12057 | 19 |
val fixed_names_of: context -> string list |
20 |
val assumptions_of: context -> (cterm list * exporter) list |
|
7557 | 21 |
val prems_of: context -> thm list |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
22 |
val fact_index_of: context -> FactIndex.T |
5874 | 23 |
val init: theory -> context |
14828 | 24 |
val pretty_term: context -> term -> Pretty.T |
25 |
val pretty_typ: context -> typ -> Pretty.T |
|
26 |
val pretty_sort: context -> sort -> Pretty.T |
|
27 |
val pp: context -> Pretty.pp |
|
28 |
val pretty_thm: context -> thm -> Pretty.T |
|
29 |
val pretty_thms: context -> thm list -> Pretty.T |
|
30 |
val pretty_fact: context -> string * thm list -> Pretty.T |
|
31 |
val string_of_term: context -> term -> string |
|
12414 | 32 |
val default_type: context -> string -> typ option |
12504 | 33 |
val used_types: context -> string list |
5819 | 34 |
val read_typ: context -> string -> typ |
16348 | 35 |
val read_typ_syntax: context -> string -> typ |
36 |
val read_typ_abbrev: context -> string -> typ |
|
5819 | 37 |
val cert_typ: context -> typ -> typ |
16348 | 38 |
val cert_typ_syntax: context -> typ -> typ |
39 |
val cert_typ_abbrev: context -> typ -> typ |
|
10583 | 40 |
val get_skolem: context -> string -> string |
9133 | 41 |
val extern_skolem: context -> term -> term |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
42 |
val read_termTs: context -> (string -> bool) -> (indexname -> typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
43 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
44 |
-> term list * (indexname * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
45 |
val read_termTs_schematic: context -> (string -> bool) -> (indexname -> typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
46 |
-> (indexname -> sort option) -> string list -> (string * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
47 |
-> term list * (indexname * typ) list |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
48 |
val read_term_liberal: context -> string -> term |
5819 | 49 |
val read_term: context -> string -> term |
50 |
val read_prop: context -> string -> term |
|
11925 | 51 |
val read_prop_schematic: context -> string -> term |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
52 |
val read_terms: context -> string list -> term list |
8096 | 53 |
val read_term_pats: typ -> context -> string list -> term list |
54 |
val read_prop_pats: context -> string list -> term list |
|
5819 | 55 |
val cert_term: context -> term -> term |
56 |
val cert_prop: context -> term -> term |
|
8096 | 57 |
val cert_term_pats: typ -> context -> term list -> term list |
58 |
val cert_prop_pats: context -> term list -> term list |
|
5819 | 59 |
val declare_term: term -> context -> context |
15703 | 60 |
val read_tyname: context -> string -> typ |
61 |
val read_const: context -> string -> term |
|
7925 | 62 |
val warn_extra_tfrees: context -> context -> context |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
63 |
val generalize: context -> context -> term list -> term list |
9470 | 64 |
val find_free: term -> string -> term option |
12008 | 65 |
val export: bool -> context -> context -> thm -> thm Seq.seq |
13415 | 66 |
val export_standard: cterm list -> context -> context -> thm -> thm |
15696 | 67 |
val export_plain: cterm list -> context -> context -> thm -> thm |
10810 | 68 |
val drop_schematic: indexname * term option -> indexname * term option |
69 |
val add_binds: (indexname * string option) list -> context -> context |
|
70 |
val add_binds_i: (indexname * term option) list -> context -> context |
|
12147 | 71 |
val auto_bind_goal: term list -> context -> context |
72 |
val auto_bind_facts: term list -> context -> context |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
73 |
val match_bind: bool -> (string list * string) list -> context -> context |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
74 |
val match_bind_i: bool -> (term list * term) list -> context -> context |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
75 |
val read_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
76 |
-> context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
77 |
val cert_propp: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
78 |
-> context * (term * (term list * term list)) list list |
10554 | 79 |
val read_propp_schematic: context * (string * (string list * string list)) list list |
80 |
-> context * (term * (term list * term list)) list list |
|
81 |
val cert_propp_schematic: context * (term * (term list * term list)) list list |
|
82 |
-> context * (term * (term list * term list)) list list |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
83 |
val bind_propp: context * (string * (string list * string list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
84 |
-> context * (term list list * (context -> context)) |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
85 |
val bind_propp_i: context * (term * (term list * term list)) list list |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
86 |
-> context * (term list list * (context -> context)) |
10554 | 87 |
val bind_propp_schematic: context * (string * (string list * string list)) list list |
88 |
-> context * (term list list * (context -> context)) |
|
89 |
val bind_propp_schematic_i: context * (term * (term list * term list)) list list |
|
90 |
-> context * (term list list * (context -> context)) |
|
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
91 |
val get_thm: context -> thmref -> thm |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
92 |
val get_thm_closure: context -> thmref -> thm |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
93 |
val get_thms: context -> thmref -> thm list |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15452
diff
changeset
|
94 |
val get_thms_closure: context -> thmref -> thm list |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
95 |
val valid_thms: context -> string * thm list -> bool |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
96 |
val lthms_containing: context -> FactIndex.spec -> (string * thm list) list |
16348 | 97 |
val extern_thm: context -> string -> xstring |
16147 | 98 |
val qualified_names: context -> context |
99 |
val no_base_names: context -> context |
|
100 |
val custom_accesses: (string list -> string list list) -> context -> context |
|
101 |
val restore_naming: context -> context -> context |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
102 |
val hide_thms: bool -> string list -> context -> context |
6091 | 103 |
val put_thm: string * thm -> context -> context |
104 |
val put_thms: string * thm list -> context -> context |
|
105 |
val put_thmss: (string * thm list) list -> context -> context |
|
7606 | 106 |
val reset_thms: string -> context -> context |
14564 | 107 |
val note_thmss: |
16147 | 108 |
((bstring * context attribute list) * (thmref * context attribute list) list) list -> |
109 |
context -> context * (bstring * thm list) list |
|
14564 | 110 |
val note_thmss_i: |
16147 | 111 |
((bstring * context attribute list) * (thm list * context attribute list) list) list -> |
112 |
context -> context * (bstring * thm list) list |
|
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
113 |
val export_assume: exporter |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
114 |
val export_presume: exporter |
12086 | 115 |
val cert_def: context -> term -> string * term |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
116 |
val export_def: exporter |
9470 | 117 |
val assume: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
118 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
12835 | 119 |
-> context -> context * (bstring * thm list) list |
9470 | 120 |
val assume_i: exporter |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
121 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
12835 | 122 |
-> context -> context * (bstring * thm list) list |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
123 |
val read_vars: context * (string list * string option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
124 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
125 |
val cert_vars: context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
126 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
127 |
val read_vars_liberal: context * (string list * string option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
128 |
-> context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
129 |
val cert_vars_liberal: context * (string list * typ option) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
130 |
-> context * (string list * typ option) |
7411 | 131 |
val fix: (string list * string option) list -> context -> context |
7663 | 132 |
val fix_i: (string list * typ option) list -> context -> context |
14643 | 133 |
val add_fixes: (string * typ option * Syntax.mixfix option) list -> context -> context |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
134 |
val add_fixes_liberal: (string * typ option * Syntax.mixfix option) list -> context -> context |
12016 | 135 |
val fix_frees: term list -> context -> context |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
136 |
val bind_skolem: context -> string list -> term -> term |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
137 |
val apply_case: RuleCases.T -> context |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
138 |
-> context * ((indexname * term option) list * (string * term list) list) |
16147 | 139 |
val get_case: context -> string -> string option list -> RuleCases.T |
140 |
val add_cases: (string * RuleCases.T option) list -> context -> context |
|
10810 | 141 |
val verbose: bool ref |
142 |
val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
143 |
val print_syntax: context -> unit |
10810 | 144 |
val print_binds: context -> unit |
12057 | 145 |
val print_lthms: context -> unit |
10810 | 146 |
val print_cases: context -> unit |
147 |
val prems_limit: int ref |
|
12057 | 148 |
val pretty_asms: context -> Pretty.T list |
10810 | 149 |
val pretty_context: context -> Pretty.T list |
5819 | 150 |
end; |
151 |
||
16540 | 152 |
structure ProofContext: PROOF_CONTEXT = |
5819 | 153 |
struct |
154 |
||
16540 | 155 |
(** generic proof contexts **) |
9470 | 156 |
|
16540 | 157 |
type context = Context.proof; |
5819 | 158 |
exception CONTEXT of string * context; |
159 |
||
16540 | 160 |
val theory_of = Context.theory_of_proof; |
16458 | 161 |
val sign_of = theory_of; |
5819 | 162 |
|
16540 | 163 |
val init = Context.init_proof; |
12057 | 164 |
|
7270 | 165 |
|
5819 | 166 |
|
16540 | 167 |
(** Isar proof context information **) |
5819 | 168 |
|
16540 | 169 |
type exporter = bool -> cterm list -> thm -> thm Seq.seq; |
5819 | 170 |
|
16540 | 171 |
datatype ctxt = |
172 |
Ctxt of |
|
173 |
{syntax: Syntax.syntax * string list * string list, (*syntax with structs and mixfixed*) |
|
174 |
asms: |
|
175 |
((cterm list * exporter) list * (*assumes: A ==> _*) |
|
176 |
(string * thm list) list) * (*prems: A |- A *) |
|
177 |
(string * string) list, (*fixes: !!x. _*) |
|
178 |
binds: (term * typ) Vartab.table, (*term bindings*) |
|
179 |
thms: NameSpace.naming * (*local thms*) |
|
180 |
thm list NameSpace.table * FactIndex.T, |
|
181 |
cases: (string * RuleCases.T) list, (*local contexts*) |
|
182 |
defs: |
|
183 |
typ Vartab.table * (*type constraints*) |
|
184 |
sort Vartab.table * (*default sorts*) |
|
185 |
string list * (*used type variables*) |
|
186 |
term list Symtab.table}; (*type variable occurrences*) |
|
5819 | 187 |
|
16540 | 188 |
fun make_ctxt (syntax, asms, binds, thms, cases, defs) = |
189 |
Ctxt {syntax = syntax, asms = asms, binds = binds, thms = thms, cases = cases, defs = defs}; |
|
5819 | 190 |
|
16540 | 191 |
structure ContextData = ProofDataFun |
16458 | 192 |
(struct |
16540 | 193 |
val name = "Isar/context"; |
194 |
type T = ctxt; |
|
195 |
fun init thy = |
|
196 |
make_ctxt ((Sign.syn_of thy, [], []), (([], []), []), Vartab.empty, |
|
197 |
(NameSpace.default_naming, NameSpace.empty_table, FactIndex.empty), [], |
|
198 |
(Vartab.empty, Vartab.empty, [], Symtab.empty)); |
|
199 |
fun print _ _ = (); |
|
16458 | 200 |
end); |
5819 | 201 |
|
16540 | 202 |
val _ = Context.add_setup [ContextData.init]; |
5819 | 203 |
|
16540 | 204 |
fun rep_context ctxt = ContextData.get ctxt |> (fn Ctxt args => args); |
5819 | 205 |
|
16540 | 206 |
fun map_context f = ContextData.map (fn Ctxt {syntax, asms, binds, thms, cases, defs} => |
207 |
make_ctxt (f (syntax, asms, binds, thms, cases, defs))); |
|
5819 | 208 |
|
16540 | 209 |
val syntax_of = #syntax o rep_context; |
5819 | 210 |
|
16540 | 211 |
val assumptions_of = #1 o #1 o #asms o rep_context; |
212 |
val prems_of = List.concat o map #2 o #2 o #1 o #asms o rep_context; |
|
213 |
val fixes_of = #2 o #asms o rep_context; |
|
214 |
val fixed_names_of = map #2 o fixes_of; |
|
5819 | 215 |
|
16540 | 216 |
val binds_of = #binds o rep_context; |
5819 | 217 |
|
16540 | 218 |
val thms_of = #thms o rep_context; |
219 |
val fact_index_of = #3 o thms_of; |
|
220 |
||
221 |
val cases_of = #cases o rep_context; |
|
5819 | 222 |
|
16540 | 223 |
val defaults_of = #defs o rep_context; |
224 |
val type_occs_of = #4 o defaults_of; |
|
5819 | 225 |
|
16540 | 226 |
fun is_fixed ctxt x = exists (equal x o #2) (fixes_of ctxt); |
227 |
fun is_known ctxt x = |
|
228 |
is_some (Vartab.lookup (#1 (defaults_of ctxt), (x, ~1))) orelse is_fixed ctxt x; |
|
5819 | 229 |
|
230 |
||
8096 | 231 |
|
12093 | 232 |
(** local syntax **) |
233 |
||
234 |
val fixedN = "\\<^fixed>"; |
|
235 |
val structN = "\\<^struct>"; |
|
236 |
||
12100 | 237 |
|
14697 | 238 |
(* translation functions *) |
14665
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
239 |
|
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
240 |
fun fixed_tr x = (fixedN ^ x, curry Term.list_comb (Syntax.free x)); |
d2e5df3d1201
index syntax: support for general expressions (input only);
wenzelm
parents:
14643
diff
changeset
|
241 |
|
12100 | 242 |
fun context_tr' ctxt = |
243 |
let |
|
244 |
val (_, structs, mixfixed) = syntax_of ctxt; |
|
245 |
||
246 |
fun tr' (t $ u) = tr' t $ tr' u |
|
247 |
| tr' (Abs (x, T, t)) = Abs (x, T, tr' t) |
|
248 |
| tr' (t as Free (x, T)) = |
|
14697 | 249 |
let val i = Library.find_index_eq x structs + 1 in |
250 |
if i = 0 andalso x mem_string mixfixed then Const (fixedN ^ x, T) |
|
14707 | 251 |
else if i = 1 andalso not (! show_structs) then |
252 |
Syntax.const "_struct" $ Syntax.const "_indexdefault" |
|
12100 | 253 |
else t |
254 |
end |
|
255 |
| tr' a = a; |
|
256 |
in tr' end; |
|
257 |
||
258 |
||
12576
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
259 |
(* add syntax *) |
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
260 |
|
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
261 |
fun mixfix_type mx = replicate (Syntax.mixfix_args mx) TypeInfer.logicT ---> TypeInfer.logicT; |
12093 | 262 |
|
263 |
local |
|
264 |
||
15531 | 265 |
fun mixfix x NONE mx = (fixedN ^ x, mixfix_type mx, Syntax.fix_mixfix x mx) |
266 |
| mixfix x (SOME T) mx = (fixedN ^ x, T, Syntax.fix_mixfix x mx); |
|
12093 | 267 |
|
15531 | 268 |
fun prep_mixfix (_, _, NONE) = NONE |
269 |
| prep_mixfix (x, opt_T, SOME mx) = SOME (mixfix x opt_T mx); |
|
12093 | 270 |
|
15531 | 271 |
fun prep_mixfix' (_, _, NONE) = NONE |
272 |
| prep_mixfix' (x, _, SOME Syntax.NoSyn) = NONE |
|
273 |
| prep_mixfix' (x, opt_T, _) = SOME (x, mixfix x opt_T (Syntax.literal x)); |
|
12093 | 274 |
|
15531 | 275 |
fun prep_struct (x, _, NONE) = SOME x |
276 |
| prep_struct _ = NONE; |
|
12093 | 277 |
|
15750 | 278 |
fun mk trs = map Syntax.mk_trfun trs; |
279 |
||
12093 | 280 |
in |
281 |
||
16540 | 282 |
fun add_syntax decls ctxt = ctxt |> |
283 |
map_context (fn ((syn, structs, mixfixed), asms, binds, thms, cases, defs) => |
|
12093 | 284 |
let |
16540 | 285 |
val is_logtype = Sign.is_logtype (theory_of ctxt); |
15570 | 286 |
val structs' = structs @ List.mapPartial prep_struct decls; |
287 |
val mxs = List.mapPartial prep_mixfix decls; |
|
288 |
val (fixed, mxs_output) = Library.split_list (List.mapPartial prep_mixfix' decls); |
|
12093 | 289 |
val trs = map fixed_tr fixed; |
290 |
val syn' = syn |
|
14901 | 291 |
|> Syntax.extend_const_gram is_logtype ("", false) mxs_output |
292 |
|> Syntax.extend_const_gram is_logtype ("", true) mxs |
|
15750 | 293 |
|> Syntax.extend_trfuns ([], mk trs, [], []); |
16540 | 294 |
in ((syn', structs', fixed @ mixfixed), asms, binds, thms, cases, defs) end); |
12093 | 295 |
|
16540 | 296 |
fun syn_of ctxt = |
297 |
let |
|
298 |
val (syn, structs, _) = syntax_of ctxt; |
|
299 |
val (atrs, trs, trs', atrs') = Syntax.struct_trfuns structs; |
|
15750 | 300 |
in syn |> Syntax.extend_trfuns (mk atrs, mk trs, mk trs', mk atrs') end; |
14697 | 301 |
|
12093 | 302 |
end; |
303 |
||
304 |
||
305 |
||
14828 | 306 |
(** pretty printing **) |
307 |
||
16458 | 308 |
fun pretty_term ctxt t = Sign.pretty_term' (syn_of ctxt) (theory_of ctxt) (context_tr' ctxt t); |
309 |
fun pretty_typ ctxt T = Sign.pretty_typ (theory_of ctxt) T; |
|
310 |
fun pretty_sort ctxt S = Sign.pretty_sort (theory_of ctxt) S; |
|
311 |
fun pretty_classrel ctxt cs = Sign.pretty_classrel (theory_of ctxt) cs; |
|
312 |
fun pretty_arity ctxt ar = Sign.pretty_arity (theory_of ctxt) ar; |
|
14828 | 313 |
|
14974
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
314 |
fun pp ctxt = Pretty.pp (pretty_term ctxt, pretty_typ ctxt, pretty_sort ctxt, |
b1ecb7859c99
avoid premature evaluation of syn_of (wastes time in conjunction with pp);
wenzelm
parents:
14901
diff
changeset
|
315 |
pretty_classrel ctxt, pretty_arity ctxt); |
14828 | 316 |
|
317 |
val string_of_term = Pretty.string_of oo pretty_term; |
|
318 |
||
319 |
fun pretty_thm ctxt thm = |
|
320 |
if ! Display.show_hyps then |
|
14876 | 321 |
Display.pretty_thm_aux (pp ctxt) false thm |
14828 | 322 |
else pretty_term ctxt (Thm.prop_of thm); |
323 |
||
324 |
fun pretty_thms ctxt [th] = pretty_thm ctxt th |
|
325 |
| pretty_thms ctxt ths = Pretty.blk (0, Pretty.fbreaks (map (pretty_thm ctxt) ths)); |
|
326 |
||
327 |
fun pretty_fact ctxt ("", ths) = pretty_thms ctxt ths |
|
328 |
| pretty_fact ctxt (a, [th]) = |
|
329 |
Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, pretty_thm ctxt th] |
|
330 |
| pretty_fact ctxt (a, ths) = |
|
331 |
Pretty.block (Pretty.fbreaks (Pretty.str (a ^ ":") :: map (pretty_thm ctxt) ths)); |
|
332 |
||
333 |
||
334 |
||
7663 | 335 |
(** default sorts and types **) |
336 |
||
16540 | 337 |
fun def_sort ctxt xi = Vartab.lookup (#2 (defaults_of ctxt), xi); |
7663 | 338 |
|
16540 | 339 |
fun def_type ctxt pattern xi = |
340 |
let val {binds, defs = (types, _, _, _), ...} = rep_context ctxt in |
|
341 |
(case Vartab.lookup (types, xi) of |
|
342 |
NONE => |
|
343 |
if pattern then NONE |
|
344 |
else Vartab.lookup (binds, xi) |> Option.map (TypeInfer.polymorphicT o #2) |
|
345 |
| some => some) |
|
346 |
end; |
|
7663 | 347 |
|
16540 | 348 |
fun default_type ctxt x = Vartab.lookup (#1 (defaults_of ctxt), (x, ~1)); |
349 |
val used_types = #3 o defaults_of; |
|
12414 | 350 |
|
7663 | 351 |
|
5819 | 352 |
|
353 |
(** prepare types **) |
|
354 |
||
9504 | 355 |
local |
356 |
||
357 |
fun read_typ_aux read ctxt s = |
|
16458 | 358 |
transform_error (read (syn_of ctxt) (theory_of ctxt, def_sort ctxt)) s |
7663 | 359 |
handle ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt); |
5819 | 360 |
|
10554 | 361 |
fun cert_typ_aux cert ctxt raw_T = |
16458 | 362 |
cert (theory_of ctxt) raw_T |
10554 | 363 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
9504 | 364 |
|
365 |
in |
|
366 |
||
16348 | 367 |
val read_typ = read_typ_aux Sign.read_typ'; |
368 |
val read_typ_syntax = read_typ_aux Sign.read_typ_syntax'; |
|
369 |
val read_typ_abbrev = read_typ_aux Sign.read_typ_abbrev'; |
|
370 |
val cert_typ = cert_typ_aux Sign.certify_typ; |
|
371 |
val cert_typ_syntax = cert_typ_aux Sign.certify_typ_syntax; |
|
372 |
val cert_typ_abbrev = cert_typ_aux Sign.certify_typ_abbrev; |
|
9504 | 373 |
|
374 |
end; |
|
375 |
||
5819 | 376 |
|
7679 | 377 |
(* internalize Skolem constants *) |
378 |
||
10583 | 379 |
fun lookup_skolem ctxt x = assoc (fixes_of ctxt, x); |
15974 | 380 |
fun get_skolem ctxt x = if_none (lookup_skolem ctxt x) x; |
7679 | 381 |
|
12504 | 382 |
fun no_skolem internal ctxt x = |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
383 |
if can Syntax.dest_skolem x then |
7679 | 384 |
raise CONTEXT ("Illegal reference to internal Skolem constant: " ^ quote x, ctxt) |
12504 | 385 |
else if not internal andalso can Syntax.dest_internal x then |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
386 |
raise CONTEXT ("Illegal reference to internal variable: " ^ quote x, ctxt) |
7679 | 387 |
else x; |
388 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
389 |
fun intern_skolem ctxt internal = |
7679 | 390 |
let |
391 |
fun intern (t as Free (x, T)) = |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
392 |
if internal x then t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
393 |
else |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
394 |
(case lookup_skolem ctxt (no_skolem false ctxt x) of |
15531 | 395 |
SOME x' => Free (x', T) |
396 |
| NONE => t) |
|
7679 | 397 |
| intern (t $ u) = intern t $ intern u |
398 |
| intern (Abs (x, T, t)) = Abs (x, T, intern t) |
|
399 |
| intern a = a; |
|
400 |
in intern end; |
|
401 |
||
402 |
||
9133 | 403 |
(* externalize Skolem constants -- for printing purposes only *) |
404 |
||
405 |
fun extern_skolem ctxt = |
|
406 |
let |
|
407 |
val rev_fixes = map Library.swap (fixes_of ctxt); |
|
408 |
||
409 |
fun extern (t as Free (x, T)) = |
|
410 |
(case assoc (rev_fixes, x) of |
|
15531 | 411 |
SOME x' => Free (if lookup_skolem ctxt x' = SOME x then x' else NameSpace.hidden x', T) |
412 |
| NONE => t) |
|
9133 | 413 |
| extern (t $ u) = extern t $ extern u |
414 |
| extern (Abs (x, T, t)) = Abs (x, T, extern t) |
|
415 |
| extern a = a; |
|
416 |
in extern end |
|
417 |
||
8096 | 418 |
|
5819 | 419 |
(** prepare terms and propositions **) |
420 |
||
421 |
(* |
|
16501 | 422 |
(1) read / certify wrt. theory of context |
5819 | 423 |
(2) intern Skolem constants |
424 |
(3) expand term bindings |
|
425 |
*) |
|
426 |
||
427 |
||
16501 | 428 |
(* read wrt. theory *) (*exception ERROR*) |
5819 | 429 |
|
16458 | 430 |
fun read_def_termTs freeze pp syn thy (types, sorts, used) sTs = |
431 |
Sign.read_def_terms' pp (Sign.is_logtype thy) syn (thy, types, sorts) used freeze sTs; |
|
5874 | 432 |
|
16458 | 433 |
fun read_def_termT freeze pp syn thy defs sT = |
434 |
apfst hd (read_def_termTs freeze pp syn thy defs [sT]); |
|
14828 | 435 |
|
16458 | 436 |
fun read_term_thy freeze pp syn thy defs s = |
437 |
#1 (read_def_termT freeze pp syn thy defs (s, TypeInfer.logicT)); |
|
5874 | 438 |
|
16458 | 439 |
fun read_prop_thy freeze pp syn thy defs s = |
440 |
#1 (read_def_termT freeze pp syn thy defs (s, propT)); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
441 |
|
16458 | 442 |
fun read_terms_thy freeze pp syn thy defs = |
443 |
#1 o read_def_termTs freeze pp syn thy defs o map (rpair TypeInfer.logicT); |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
444 |
|
16458 | 445 |
fun read_props_thy freeze pp syn thy defs = |
446 |
#1 o read_def_termTs freeze pp syn thy defs o map (rpair propT); |
|
5819 | 447 |
|
448 |
||
449 |
(* norm_term *) |
|
450 |
||
451 |
(*beta normal form for terms (not eta normal form), chase variables in |
|
452 |
bindings environment (code taken from Pure/envir.ML)*) |
|
453 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
454 |
fun unifyT ctxt (T, U) = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
455 |
let val maxidx = Int.max (Term.maxidx_of_typ T, Term.maxidx_of_typ U) |
16458 | 456 |
in #1 (Type.unify (Sign.tsig_of (theory_of ctxt)) (Vartab.empty, maxidx) (T, U)) end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
457 |
|
16540 | 458 |
fun norm_term ctxt schematic = |
5819 | 459 |
let |
460 |
(*raised when norm has no effect on a term, to do sharing instead of copying*) |
|
461 |
exception SAME; |
|
462 |
||
16540 | 463 |
val binds = binds_of ctxt; |
5819 | 464 |
fun norm (t as Var (xi, T)) = |
465 |
(case Vartab.lookup (binds, xi) of |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
466 |
SOME (u, U) => |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
467 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
468 |
val env = unifyT ctxt (T, U) handle Type.TUNIFY => |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
469 |
raise TYPE ("norm_term: ill-typed variable assignment", [T, U], [t, u]); |
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15758
diff
changeset
|
470 |
val u' = Envir.subst_TVars env u; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
471 |
in norm u' handle SAME => u' end |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
472 |
| NONE => |
10554 | 473 |
if schematic then raise SAME |
474 |
else raise CONTEXT ("Unbound schematic variable: " ^ Syntax.string_of_vname xi, ctxt)) |
|
5819 | 475 |
| norm (Abs (a, T, body)) = Abs (a, T, norm body) |
476 |
| norm (Abs (_, _, body) $ t) = normh (subst_bound (t, body)) |
|
477 |
| norm (f $ t) = |
|
478 |
((case norm f of |
|
479 |
Abs (_, _, body) => normh (subst_bound (t, body)) |
|
480 |
| nf => nf $ (norm t handle SAME => t)) handle SAME => f $ norm t) |
|
481 |
| norm _ = raise SAME |
|
482 |
and normh t = norm t handle SAME => t |
|
483 |
in normh end; |
|
484 |
||
485 |
||
6550 | 486 |
(* dummy patterns *) |
487 |
||
9540 | 488 |
fun prepare_dummies t = #2 (Term.replace_dummy_patterns (1, t)); |
6762 | 489 |
|
9540 | 490 |
fun reject_dummies ctxt t = Term.no_dummy_patterns t |
491 |
handle TERM _ => raise CONTEXT ("Illegal dummy pattern(s) in term", ctxt); |
|
6550 | 492 |
|
493 |
||
5819 | 494 |
(* read terms *) |
495 |
||
10554 | 496 |
local |
497 |
||
15531 | 498 |
fun append_env e1 e2 x = (case e2 x of NONE => e1 x | some => some); |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
499 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
500 |
fun gen_read' read app pattern schematic |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
501 |
ctxt internal more_types more_sorts more_used s = |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
502 |
let |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
503 |
val types = append_env (def_type ctxt pattern) more_types; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
504 |
val sorts = append_env (def_sort ctxt) more_sorts; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
505 |
val used = used_types ctxt @ more_used; |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
506 |
in |
16458 | 507 |
(transform_error (read (pp ctxt) (syn_of ctxt) (theory_of ctxt) (types, sorts, used)) s |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
13629
diff
changeset
|
508 |
handle TERM (msg, _) => raise CONTEXT (msg, ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
509 |
| ERROR_MESSAGE msg => raise CONTEXT (msg, ctxt)) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
510 |
|> app (intern_skolem ctxt internal) |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
511 |
|> app (if pattern then I else norm_term ctxt schematic) |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
512 |
|> app (if pattern then prepare_dummies else reject_dummies ctxt) |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
513 |
end; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
514 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
515 |
fun gen_read read app pattern schematic ctxt = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
516 |
gen_read' read app pattern schematic ctxt (K false) (K NONE) (K NONE) []; |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
517 |
|
10554 | 518 |
in |
519 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
520 |
val read_termTs = gen_read' (read_def_termTs false) (apfst o map) false false; |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
521 |
val read_termTs_schematic = gen_read' (read_def_termTs false) (apfst o map) false true; |
8096 | 522 |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
523 |
fun read_term_pats T ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
524 |
#1 o gen_read (read_def_termTs false) (apfst o map) true false ctxt o map (rpair T); |
8096 | 525 |
val read_prop_pats = read_term_pats propT; |
526 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
527 |
fun read_term_liberal ctxt = |
16458 | 528 |
gen_read' (read_term_thy true) I false false ctxt (K true) (K NONE) (K NONE) []; |
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
529 |
|
16458 | 530 |
val read_term = gen_read (read_term_thy true) I false false; |
531 |
val read_prop = gen_read (read_prop_thy true) I false false; |
|
532 |
val read_prop_schematic = gen_read (read_prop_thy true) I false true; |
|
533 |
val read_terms = gen_read (read_terms_thy true) map false false; |
|
534 |
fun read_props schematic = gen_read (read_props_thy true) map false schematic; |
|
5819 | 535 |
|
10554 | 536 |
end; |
537 |
||
5819 | 538 |
|
539 |
(* certify terms *) |
|
540 |
||
10554 | 541 |
local |
542 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
543 |
fun gen_cert cert pattern schematic ctxt t = t |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
544 |
|> (if pattern then I else norm_term ctxt schematic) |
16458 | 545 |
|> (fn t' => cert (pp ctxt) (theory_of ctxt) t' |
16501 | 546 |
handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt) |
547 |
| TERM (msg, _) => raise CONTEXT (msg, ctxt)); |
|
548 |
||
549 |
val certify_term = #1 ooo Sign.certify_term; |
|
550 |
val certify_prop = #1 ooo Sign.certify_prop; |
|
5819 | 551 |
|
10554 | 552 |
in |
8096 | 553 |
|
16501 | 554 |
val cert_term = gen_cert certify_term false false; |
555 |
val cert_prop = gen_cert certify_prop false false; |
|
556 |
val cert_props = map oo gen_cert certify_prop false; |
|
10554 | 557 |
|
16501 | 558 |
fun cert_term_pats _ = map o gen_cert certify_term true false; |
559 |
val cert_prop_pats = map o gen_cert certify_prop true false; |
|
10554 | 560 |
|
561 |
end; |
|
5819 | 562 |
|
563 |
||
564 |
(* declare terms *) |
|
565 |
||
10381 | 566 |
local |
567 |
||
16861 | 568 |
val ins_types = fold_aterms |
569 |
(fn Free (x, T) => curry Vartab.update ((x, ~1), T) |
|
570 |
| Var v => curry Vartab.update v |
|
571 |
| _ => I); |
|
5819 | 572 |
|
16861 | 573 |
val ins_sorts = fold_types (fold_atyps |
574 |
(fn TFree (x, S) => curry Vartab.update ((x, ~1), S) |
|
575 |
| TVar v => curry Vartab.update v |
|
576 |
| _ => I)); |
|
5819 | 577 |
|
16861 | 578 |
val ins_used = fold_term_types (fn t => |
579 |
fold_atyps (fn TFree (x, _) => insert (op =) x | _ => I)); |
|
12291 | 580 |
|
16861 | 581 |
val ins_occs = fold_term_types (fn t => |
582 |
fold_atyps (fn TFree (x, _) => curry Symtab.update_multi (x, t) | _ => I)); |
|
5819 | 583 |
|
16861 | 584 |
fun ins_skolem def_ty = fold_rev (fn (x, x') => |
585 |
(case def_ty x' of |
|
586 |
SOME T => curry Vartab.update ((x, ~1), T) |
|
587 |
| NONE => I)); |
|
5994 | 588 |
|
16540 | 589 |
fun map_defaults f = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
590 |
(syntax, asms, binds, thms, cases, f defs)); |
|
5819 | 591 |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
592 |
in |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
593 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
594 |
fun declare_term_syntax t ctxt = |
5819 | 595 |
ctxt |
16861 | 596 |
|> map_defaults (fn (types, sorts, used, occ) => (ins_types t types, sorts, used, occ)) |
597 |
|> map_defaults (fn (types, sorts, used, occ) => (types, ins_sorts t sorts, used, occ)) |
|
598 |
|> map_defaults (fn (types, sorts, used, occ) => (types, sorts, ins_used t used, occ)); |
|
10381 | 599 |
|
16540 | 600 |
fun declare_term t ctxt = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
601 |
ctxt |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
602 |
|> declare_term_syntax t |
16861 | 603 |
|> map_defaults (fn (types, sorts, used, occ) => (types, sorts, used, ins_occs t occ)) |
12291 | 604 |
|> map_defaults (fn (types, sorts, used, occ) => |
16861 | 605 |
(ins_skolem (fn x => Vartab.lookup (types, (x, ~1))) (fixes_of ctxt) types, |
606 |
sorts, used, occ)); |
|
5819 | 607 |
|
10381 | 608 |
end; |
5819 | 609 |
|
610 |
||
15703 | 611 |
(* type and constant names *) |
612 |
||
613 |
fun read_tyname ctxt c = |
|
614 |
if c mem_string used_types ctxt then |
|
16458 | 615 |
TFree (c, if_none (def_sort ctxt (c, ~1)) (Sign.defaultS (theory_of ctxt))) |
616 |
else Sign.read_tyname (theory_of ctxt) c; |
|
15703 | 617 |
|
618 |
fun read_const ctxt c = |
|
619 |
(case lookup_skolem ctxt c of |
|
620 |
SOME c' => Free (c', dummyT) |
|
16458 | 621 |
| NONE => Sign.read_const (theory_of ctxt) c); |
15703 | 622 |
|
623 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
624 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
625 |
(** Hindley-Milner polymorphism **) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
626 |
|
7925 | 627 |
(* warn_extra_tfrees *) |
628 |
||
16540 | 629 |
fun warn_extra_tfrees ctxt1 ctxt2 = |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
630 |
let |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
631 |
fun known_tfree a (Type (_, Ts)) = exists (known_tfree a) Ts |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
632 |
| known_tfree a (TFree (a', _)) = a = a' |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
633 |
| known_tfree _ _ = false; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
634 |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
635 |
val extras = |
16540 | 636 |
Library.gen_rems Library.eq_fst (pairself (Symtab.dest o type_occs_of) (ctxt1, ctxt2)) |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
637 |
|> map (fn (a, ts) => map (pair a) (List.mapPartial (try (#1 o Term.dest_Free)) ts)) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
638 |
|> List.concat |
15570 | 639 |
|> List.mapPartial (fn (a, x) => |
15531 | 640 |
(case def_type ctxt1 false (x, ~1) of NONE => SOME (a, x) |
641 |
| SOME T => if known_tfree a T then NONE else SOME (a, x))); |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
642 |
val tfrees = map #1 extras |> Library.sort_strings |> Library.unique_strings; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
643 |
val frees = map #2 extras |> Library.sort_strings |> Library.unique_strings; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
644 |
in |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
645 |
if null extras then () |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
646 |
else warning ("Just introduced free type variable(s): " ^ commas tfrees ^ " in " ^ |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
647 |
space_implode " or " frees); |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
648 |
ctxt2 |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
649 |
end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
650 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
651 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
652 |
(* generalize type variables *) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
653 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
654 |
fun generalize_tfrees inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
655 |
let |
12057 | 656 |
val extra_fixes = fixed_names_of inner \\ fixed_names_of outer; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
657 |
fun still_fixed (Free (x, _)) = not (x mem_string extra_fixes) |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
658 |
| still_fixed _ = false; |
16540 | 659 |
val occs_inner = type_occs_of inner; |
660 |
val occs_outer = type_occs_of outer; |
|
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
661 |
fun add a gen = |
15974 | 662 |
if is_some (Symtab.lookup (occs_outer, a)) orelse |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
663 |
exists still_fixed (Symtab.lookup_multi (occs_inner, a)) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
664 |
then gen else a :: gen; |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
665 |
in fn tfrees => fold add tfrees [] end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
666 |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
667 |
fun generalize inner outer ts = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
668 |
let |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
669 |
val tfrees = generalize_tfrees inner outer (foldr Term.add_term_tfree_names [] ts); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
670 |
fun gen (x, S) = if x mem_string tfrees then TVar ((x, 0), S) else TFree (x, S); |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
671 |
in map (Term.map_term_types (Term.map_type_tfree gen)) ts end; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
672 |
|
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
673 |
|
9553 | 674 |
|
675 |
(** export theorems **) |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
676 |
|
16861 | 677 |
fun get_free x (t as Free (y, _)) NONE = if x = y then SOME t else NONE |
678 |
| get_free _ _ opt = opt; |
|
16790 | 679 |
|
16861 | 680 |
fun find_free t x = fold_aterms (get_free x) t NONE; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
681 |
|
13415 | 682 |
fun export_view view is_goal inner outer = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
683 |
let |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
684 |
val gen = generalize_tfrees inner outer; |
12057 | 685 |
val fixes = fixed_names_of inner \\ fixed_names_of outer; |
686 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
11816 | 687 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
688 |
in fn thm => thm |
12804 | 689 |
|> Tactic.norm_hhf_rule |
11816 | 690 |
|> Seq.EVERY (rev exp_asms) |
13415 | 691 |
|> Seq.map (Drule.implies_intr_list view) |
11816 | 692 |
|> Seq.map (fn rule => |
693 |
let |
|
16458 | 694 |
val {thy, prop, ...} = Thm.rep_thm rule; |
695 |
val frees = map (Thm.cterm_of thy) (List.mapPartial (find_free prop) fixes); |
|
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
696 |
val tfrees = gen (Term.add_term_tfree_names (prop, [])); |
11816 | 697 |
in |
698 |
rule |
|
699 |
|> Drule.forall_intr_list frees |
|
12804 | 700 |
|> Tactic.norm_hhf_rule |
12504 | 701 |
|> (#1 o Drule.tvars_intr_list tfrees) |
11816 | 702 |
end) |
703 |
end; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
704 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
705 |
(*without varification*) |
15696 | 706 |
fun export_view' view is_goal inner outer = |
707 |
let |
|
708 |
val asms = Library.drop (length (assumptions_of outer), assumptions_of inner); |
|
709 |
val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms; |
|
710 |
in fn thm =>thm |
|
711 |
|> Tactic.norm_hhf_plain |
|
712 |
|> Seq.EVERY (rev exp_asms) |
|
713 |
|> Seq.map (Drule.implies_intr_list view) |
|
714 |
|> Seq.map Tactic.norm_hhf_plain |
|
715 |
end; |
|
716 |
||
13415 | 717 |
val export = export_view []; |
13399
c136276dc847
support locale ``views'' (for cumulative predicates);
wenzelm
parents:
13378
diff
changeset
|
718 |
|
15696 | 719 |
fun gen_export_std exp_view view inner outer = |
720 |
let val exp = exp_view view false inner outer in |
|
13378 | 721 |
fn th => |
722 |
(case Seq.pull (exp th) of |
|
15531 | 723 |
SOME (th', _) => th' |> Drule.local_standard |
16850 | 724 |
| NONE => sys_error "Failed to export theorem") |
13378 | 725 |
end; |
12704 | 726 |
|
15696 | 727 |
val export_standard = gen_export_std export_view; |
728 |
val export_plain = gen_export_std export_view'; |
|
7925 | 729 |
|
5819 | 730 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
731 |
|
5819 | 732 |
(** bindings **) |
733 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
734 |
(* delete_update_binds *) |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
735 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
736 |
local |
5819 | 737 |
|
16540 | 738 |
fun del_bind xi = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
739 |
(syntax, asms, Vartab.delete_safe xi binds, thms, cases, defs)); |
|
7606 | 740 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
741 |
fun upd_bind ((x, i), t) = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
742 |
let |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
743 |
val T = Term.fastype_of t; |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
744 |
val t' = |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
745 |
if null (Term.term_tvars t \\ Term.typ_tvars T) then t |
8637 | 746 |
else Var ((x ^ "_has_extra_type_vars_on_rhs", i), T); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
747 |
in |
16540 | 748 |
map_context (fn (syntax, asms, binds, thms, cases, defs) => |
749 |
(syntax, asms, Vartab.update (((x, i), (t', T)), binds), thms, cases, defs)) |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
750 |
o declare_term t' |
5819 | 751 |
end; |
752 |
||
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
753 |
fun del_upd_bind (xi, NONE) = del_bind xi |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
754 |
| del_upd_bind (xi, SOME t) = upd_bind (xi, t); |
7606 | 755 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
756 |
in |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
757 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
758 |
val delete_update_binds = fold del_upd_bind; |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
759 |
|
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
760 |
end; |
7606 | 761 |
|
5819 | 762 |
|
8096 | 763 |
(* simult_matches *) |
764 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
765 |
fun simult_matches ctxt [] = [] |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
766 |
| simult_matches ctxt pairs = |
8096 | 767 |
let |
10554 | 768 |
fun fail () = raise CONTEXT ("Pattern match failed!", ctxt); |
769 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
770 |
val maxidx = fold (fn (t1, t2) => fn i => |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
771 |
Int.max (Int.max (Term.maxidx_of_term t1, Term.maxidx_of_term t2), i)) pairs ~1; |
16458 | 772 |
val envs = Unify.smash_unifiers (theory_of ctxt, Envir.empty maxidx, |
10554 | 773 |
map swap pairs); (*prefer assignment of variables from patterns*) |
774 |
val env = |
|
8096 | 775 |
(case Seq.pull envs of |
15531 | 776 |
NONE => fail () |
777 |
| SOME (env, _) => env); (*ignore further results*) |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
778 |
val domain = |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
779 |
filter_out Term.is_replaced_dummy_pattern (map #1 (Drule.vars_of_terms (map #1 pairs))); |
10554 | 780 |
val _ = (*may not assign variables from text*) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
781 |
if null (map #1 (Envir.alist_of env) inter (map #1 (Drule.vars_of_terms (map #2 pairs)))) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
782 |
then () else fail (); |
15798
016f3be5a5ec
Adapted to new interface of instantiation and unification / matching functions.
berghofe
parents:
15758
diff
changeset
|
783 |
fun norm_bind (xi, (_, t)) = if xi mem domain then SOME (xi, Envir.norm_term env t) else NONE; |
15570 | 784 |
in List.mapPartial norm_bind (Envir.alist_of env) end; |
8096 | 785 |
|
786 |
||
787 |
(* add_binds(_i) *) |
|
5819 | 788 |
|
7925 | 789 |
local |
790 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
791 |
fun gen_bind prep (xi as (x, _), raw_t) ctxt = |
15570 | 792 |
ctxt |> delete_update_binds [(xi, Option.map (prep ctxt) raw_t)]; |
5819 | 793 |
|
10810 | 794 |
in |
795 |
||
15531 | 796 |
fun drop_schematic (b as (xi, SOME t)) = if null (Term.term_vars t) then b else (xi, NONE) |
10554 | 797 |
| drop_schematic b = b; |
798 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
799 |
val add_binds = fold (gen_bind read_term); |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
800 |
val add_binds_i = fold (gen_bind cert_term); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
801 |
|
16458 | 802 |
fun auto_bind f ts ctxt = ctxt |> add_binds_i (map drop_schematic (f (theory_of ctxt) ts)); |
12147 | 803 |
val auto_bind_goal = auto_bind AutoBind.goal; |
804 |
val auto_bind_facts = auto_bind AutoBind.facts; |
|
7925 | 805 |
|
806 |
end; |
|
5819 | 807 |
|
808 |
||
8096 | 809 |
(* match_bind(_i) *) |
5819 | 810 |
|
8096 | 811 |
local |
812 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
813 |
fun prep_bind prep_pats (ctxt, (raw_pats, t)) = |
5819 | 814 |
let |
8096 | 815 |
val ctxt' = declare_term t ctxt; |
816 |
val pats = prep_pats (fastype_of t) ctxt' raw_pats; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
817 |
val binds = simult_matches ctxt' (map (rpair t) pats); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
818 |
in (ctxt', binds) end; |
7670 | 819 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
820 |
fun gen_binds prep_terms prep_pats gen raw_binds ctxt = |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
821 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
822 |
val ts = prep_terms ctxt (map snd raw_binds); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
823 |
val (ctxt', binds) = |
15570 | 824 |
apsnd List.concat (foldl_map (prep_bind prep_pats) (ctxt, map fst raw_binds ~~ ts)); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
825 |
val binds' = |
12550
32843ad8160a
generalize type variables properly: start with occurrences in objects
wenzelm
parents:
12530
diff
changeset
|
826 |
if gen then map #1 binds ~~ generalize ctxt' ctxt (map #2 binds) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
827 |
else binds; |
15531 | 828 |
val binds'' = map (apsnd SOME) binds'; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
829 |
in |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
830 |
warn_extra_tfrees ctxt |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
831 |
(if gen then |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
832 |
ctxt (*sic!*) |> fold declare_term (map #2 binds') |> add_binds_i binds'' |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
833 |
else ctxt' |> add_binds_i binds'') |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
834 |
end; |
8096 | 835 |
|
836 |
in |
|
5935 | 837 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
838 |
val match_bind = gen_binds read_terms read_term_pats; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
839 |
val match_bind_i = gen_binds (map o cert_term) cert_term_pats; |
8096 | 840 |
|
841 |
end; |
|
5935 | 842 |
|
843 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
844 |
(* propositions with patterns *) |
5935 | 845 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
846 |
local |
8096 | 847 |
|
10554 | 848 |
fun prep_propp schematic prep_props prep_pats (context, args) = |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
849 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
850 |
fun prep ((ctxt, prop :: props), (_, (raw_pats1, raw_pats2))) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
851 |
let |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
852 |
val ctxt' = declare_term prop ctxt; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
853 |
val pats = prep_pats ctxt' (raw_pats1 @ raw_pats2); (*simultaneous type inference!*) |
13629 | 854 |
in ((ctxt', props), (prop, splitAt(length raw_pats1, pats))) end |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
855 |
| prep _ = sys_error "prep_propp"; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
856 |
val ((context', _), propp) = foldl_map (foldl_map prep) |
15570 | 857 |
((context, prep_props schematic context (List.concat (map (map fst) args))), args); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
858 |
in (context', propp) end; |
5935 | 859 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
860 |
fun matches ctxt (prop, (pats1, pats2)) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
861 |
simult_matches ctxt (map (rpair prop) pats1 @ map (rpair (Logic.strip_imp_concl prop)) pats2); |
8096 | 862 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
863 |
fun gen_bind_propp prepp (ctxt, raw_args) = |
8096 | 864 |
let |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
865 |
val (ctxt', args) = prepp (ctxt, raw_args); |
15570 | 866 |
val binds = List.concat (List.concat (map (map (matches ctxt')) args)); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
867 |
val propss = map (map #1) args; |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
868 |
|
10554 | 869 |
(*generalize result: context evaluated now, binds added later*) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
870 |
val gen = generalize ctxt' ctxt; |
15531 | 871 |
fun gen_binds c = c |> add_binds_i (map #1 binds ~~ map SOME (gen (map #2 binds))); |
872 |
in (ctxt' |> add_binds_i (map (apsnd SOME) binds), (propss, gen_binds)) end; |
|
8096 | 873 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
874 |
in |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
875 |
|
11925 | 876 |
val read_propp = prep_propp false read_props read_prop_pats; |
877 |
val cert_propp = prep_propp false cert_props cert_prop_pats; |
|
10554 | 878 |
val read_propp_schematic = prep_propp true read_props read_prop_pats; |
879 |
val cert_propp_schematic = prep_propp true cert_props cert_prop_pats; |
|
880 |
||
11925 | 881 |
val bind_propp = gen_bind_propp read_propp; |
882 |
val bind_propp_i = gen_bind_propp cert_propp; |
|
883 |
val bind_propp_schematic = gen_bind_propp read_propp_schematic; |
|
10554 | 884 |
val bind_propp_schematic_i = gen_bind_propp cert_propp_schematic; |
6789 | 885 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
886 |
end; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
887 |
|
6789 | 888 |
|
5819 | 889 |
|
890 |
(** theorems **) |
|
891 |
||
6091 | 892 |
(* get_thm(s) *) |
5819 | 893 |
|
9566 | 894 |
(*beware of proper order of evaluation!*) |
16540 | 895 |
fun retrieve_thms from_thy pick ctxt = |
896 |
let |
|
897 |
val thy_ref = Theory.self_ref (theory_of ctxt); |
|
898 |
val (_, (space, tab), _) = thms_of ctxt; |
|
899 |
in |
|
16501 | 900 |
fn xthmref => |
901 |
let |
|
16540 | 902 |
val thy = Theory.deref thy_ref; |
16501 | 903 |
val thmref = PureThy.map_name_of_thmref (NameSpace.intern space) xthmref; |
904 |
val name = PureThy.name_of_thmref thmref; |
|
905 |
in |
|
906 |
(case Symtab.lookup (tab, name) of |
|
16540 | 907 |
SOME ths => map (Thm.transfer thy) (PureThy.select_thm thmref ths) |
908 |
| NONE => from_thy thy xthmref) |> pick name |
|
16501 | 909 |
end |
9566 | 910 |
end; |
5819 | 911 |
|
9566 | 912 |
val get_thm = retrieve_thms PureThy.get_thms PureThy.single_thm; |
913 |
val get_thm_closure = retrieve_thms PureThy.get_thms_closure PureThy.single_thm; |
|
914 |
val get_thms = retrieve_thms PureThy.get_thms (K I); |
|
915 |
val get_thms_closure = retrieve_thms PureThy.get_thms_closure (K I); |
|
5819 | 916 |
|
917 |
||
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
918 |
(* valid_thms *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
919 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
920 |
fun valid_thms ctxt (name, ths) = |
16501 | 921 |
(case try (transform_error (fn () => get_thms ctxt (Name name))) () of |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
922 |
NONE => false |
16147 | 923 |
| SOME ths' => Thm.eq_thms (ths, ths')); |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
924 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
925 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
926 |
(* lthms_containing *) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
927 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
928 |
fun lthms_containing ctxt spec = |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
929 |
FactIndex.find (fact_index_of ctxt) spec |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
930 |
|> List.filter (valid_thms ctxt) |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
931 |
|> gen_distinct eq_fst; |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
932 |
|
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
933 |
|
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
934 |
(* name space operations *) |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
935 |
|
16540 | 936 |
val extern_thm = NameSpace.extern o #1 o #2 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
937 |
|
16540 | 938 |
fun map_naming f = map_context (fn (syntax, asms, binds, |
16348 | 939 |
(naming, table, index), cases, defs) => |
16540 | 940 |
(syntax, asms, binds, (f naming, table, index), cases, defs)); |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
941 |
|
16147 | 942 |
val qualified_names = map_naming NameSpace.qualified_names; |
943 |
val no_base_names = map_naming NameSpace.no_base_names; |
|
944 |
val custom_accesses = map_naming o NameSpace.custom_accesses; |
|
16540 | 945 |
val restore_naming = map_naming o K o #1 o thms_of; |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
946 |
|
16348 | 947 |
fun hide_thms fully names = map_context |
16540 | 948 |
(fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
949 |
(syntax, asms, binds, |
|
16348 | 950 |
(naming, (fold (NameSpace.hide fully) names space, tab), index), cases, defs)); |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
951 |
|
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
952 |
|
6091 | 953 |
(* put_thm(s) *) |
5819 | 954 |
|
16147 | 955 |
fun put_thms ("", _) ctxt = ctxt |
956 |
| put_thms (bname, ths) ctxt = ctxt |> map_context |
|
16540 | 957 |
(fn (syntax, asms, binds, (naming, (space, tab), index), cases, defs) => |
16147 | 958 |
let |
959 |
val name = NameSpace.full naming bname; |
|
960 |
val space' = NameSpace.declare naming name space; |
|
961 |
val tab' = Symtab.update ((name, ths), tab); |
|
962 |
val index' = FactIndex.add (is_known ctxt) (name, ths) index; |
|
16540 | 963 |
in (syntax, asms, binds, (naming, (space', tab'), index'), cases, defs) end); |
5819 | 964 |
|
16147 | 965 |
fun put_thm (name, th) = put_thms (name, [th]); |
966 |
val put_thmss = fold put_thms; |
|
5819 | 967 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
968 |
|
7606 | 969 |
(* reset_thms *) |
970 |
||
16540 | 971 |
fun reset_thms name = (* FIXME NameSpace.hide!? *) |
972 |
map_context (fn (syntax, asms, binds, (q, (space, tab), index), cases, defs) => |
|
973 |
(syntax, asms, binds, (q, (space, Symtab.delete_safe name tab), index), cases, defs)); |
|
7606 | 974 |
|
975 |
||
14564 | 976 |
(* note_thmss *) |
5819 | 977 |
|
12711 | 978 |
local |
16147 | 979 |
|
980 |
fun gen_note_thss get (ctxt, ((name, more_attrs), ths_attrs)) = |
|
5819 | 981 |
let |
982 |
fun app ((ct, ths), (th, attrs)) = |
|
12711 | 983 |
let val (ct', th') = Thm.applys_attributes ((ct, get ctxt th), attrs @ more_attrs) |
984 |
in (ct', th' :: ths) end; |
|
15570 | 985 |
val (ctxt', rev_thms) = Library.foldl app ((ctxt, []), ths_attrs); |
986 |
val thms = List.concat (rev rev_thms); |
|
16147 | 987 |
in (ctxt' |> put_thms (name, thms), (name, thms)) end; |
5819 | 988 |
|
16147 | 989 |
fun gen_note_thmss get args ctxt = |
990 |
foldl_map (gen_note_thss get) (ctxt, args); |
|
12711 | 991 |
|
992 |
in |
|
993 |
||
16147 | 994 |
val note_thmss = gen_note_thmss get_thms; |
995 |
val note_thmss_i = gen_note_thmss (K I); |
|
15696 | 996 |
|
997 |
val note_thmss_accesses = gen_note_thmss get_thms; |
|
998 |
val note_thmss_accesses_i = gen_note_thmss (K I); |
|
12711 | 999 |
|
1000 |
end; |
|
9196 | 1001 |
|
5819 | 1002 |
|
1003 |
||
1004 |
(** assumptions **) |
|
1005 |
||
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1006 |
(* basic exporters *) |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1007 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1008 |
fun export_assume true = Seq.single oo Drule.implies_intr_goals |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1009 |
| export_assume false = Seq.single oo Drule.implies_intr_list; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1010 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1011 |
fun export_presume _ = export_assume false; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1012 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1013 |
|
12057 | 1014 |
(* defs *) |
1015 |
||
12066 | 1016 |
fun cert_def ctxt eq = |
12016 | 1017 |
let |
12057 | 1018 |
fun err msg = raise CONTEXT (msg ^ |
1019 |
"\nThe error(s) above occurred in local definition: " ^ string_of_term ctxt eq, ctxt); |
|
1020 |
val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq) |
|
1021 |
handle TERM _ => err "Not a meta-equality (==)"; |
|
12086 | 1022 |
val (f, xs) = Term.strip_comb lhs; |
1023 |
val (c, _) = Term.dest_Free f handle TERM _ => |
|
13430 | 1024 |
err "Head of lhs must be a free/fixed variable"; |
12057 | 1025 |
|
12086 | 1026 |
fun is_free (Free (x, _)) = not (is_fixed ctxt x) |
1027 |
| is_free _ = false; |
|
15570 | 1028 |
val extra_frees = List.filter is_free (term_frees rhs) \\ xs; |
12016 | 1029 |
in |
12086 | 1030 |
conditional (not (forall (is_Bound orf is_free) xs andalso null (duplicates xs))) (fn () => |
13430 | 1031 |
err "Arguments of lhs must be distinct free/bound variables"); |
12086 | 1032 |
conditional (f mem Term.term_frees rhs) (fn () => |
1033 |
err "Element to be defined occurs on rhs"); |
|
1034 |
conditional (not (null extra_frees)) (fn () => |
|
1035 |
err ("Extra free variables on rhs: " ^ commas_quote (map (#1 o dest_Free) extra_frees))); |
|
15570 | 1036 |
(c, Term.list_all_free (List.mapPartial (try Term.dest_Free) xs, eq)) |
12057 | 1037 |
end; |
1038 |
||
1039 |
fun head_of_def cprop = |
|
1040 |
#1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop))))) |
|
16458 | 1041 |
|> Thm.cterm_of (Thm.theory_of_cterm cprop); |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1042 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1043 |
fun export_def _ cprops thm = |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1044 |
thm |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1045 |
|> Drule.implies_intr_list cprops |
12057 | 1046 |
|> Drule.forall_intr_list (map head_of_def cprops) |
11918
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1047 |
|> Drule.forall_elim_vars 0 |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1048 |
|> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1; |
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1049 |
|
dfdf0798d7b8
added export_assume, export_presume, export_def (from proof.ML);
wenzelm
parents:
11915
diff
changeset
|
1050 |
|
5819 | 1051 |
(* assume *) |
1052 |
||
7270 | 1053 |
local |
6797 | 1054 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1055 |
fun add_assm (ctxt, ((name, attrs), props)) = |
5819 | 1056 |
let |
16458 | 1057 |
val cprops = map (Thm.cterm_of (theory_of ctxt)) props; |
12804 | 1058 |
val asms = map (Tactic.norm_hhf_rule o Thm.assume) cprops; |
5919 | 1059 |
|
1060 |
val ths = map (fn th => ([th], [])) asms; |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1061 |
val (ctxt', [(_, thms)]) = |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1062 |
ctxt |
12147 | 1063 |
|> auto_bind_facts props |
14564 | 1064 |
|> note_thmss_i [((name, attrs), ths)]; |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1065 |
in (ctxt', (cprops, (name, asms), (name, thms))) end; |
5819 | 1066 |
|
9470 | 1067 |
fun gen_assms prepp exp args ctxt = |
1068 |
let |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1069 |
val (ctxt1, propss) = prepp (ctxt, map snd args); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1070 |
val (ctxt2, results) = foldl_map add_assm (ctxt1, map fst args ~~ propss); |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
1071 |
|
15570 | 1072 |
val cprops = List.concat (map #1 results); |
9470 | 1073 |
val asmss = map #2 results; |
1074 |
val thmss = map #3 results; |
|
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1075 |
val ctxt3 = ctxt2 |> map_context |
16540 | 1076 |
(fn (syntax, ((asms_ct, asms_th), fixes), binds, thms, cases, defs) => |
1077 |
(syntax, ((asms_ct @ [(cprops, exp)], asms_th @ asmss), fixes), binds, thms, |
|
15735 | 1078 |
cases, defs)); |
11925 | 1079 |
val ctxt4 = ctxt3 |> put_thms ("prems", prems_of ctxt3); |
1080 |
in (warn_extra_tfrees ctxt ctxt4, thmss) end; |
|
5819 | 1081 |
|
7270 | 1082 |
in |
1083 |
||
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
1084 |
val assume = gen_assms (apsnd #1 o bind_propp); |
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
1085 |
val assume_i = gen_assms (apsnd #1 o bind_propp_i); |
7270 | 1086 |
|
1087 |
end; |
|
5819 | 1088 |
|
1089 |
||
8096 | 1090 |
(* variables *) |
1091 |
||
10381 | 1092 |
local |
1093 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1094 |
fun prep_vars prep_typ internal liberal (ctxt, (xs, raw_T)) = |
8096 | 1095 |
let |
12504 | 1096 |
fun cond_tvars T = |
1097 |
if internal then T |
|
1098 |
else Type.no_tvars T handle TYPE (msg, _, _) => raise CONTEXT (msg, ctxt); |
|
1099 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1100 |
val _ = if liberal then () else |
15570 | 1101 |
(case List.filter (not o Syntax.is_identifier) (map (no_skolem internal ctxt) xs) of |
8096 | 1102 |
[] => () | bads => raise CONTEXT ("Bad variable name(s): " ^ commas_quote bads, ctxt)); |
1103 |
||
15570 | 1104 |
val opt_T = Option.map (cond_tvars o prep_typ ctxt) raw_T; |
15974 | 1105 |
val T = if_none opt_T TypeInfer.logicT; |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1106 |
val ctxt' = ctxt |> fold declare_term_syntax (map (fn x => Free (x, T)) xs); |
8096 | 1107 |
in (ctxt', (xs, opt_T)) end; |
1108 |
||
10381 | 1109 |
in |
1110 |
||
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1111 |
val read_vars = prep_vars read_typ false false; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1112 |
val cert_vars = prep_vars cert_typ true false; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1113 |
val read_vars_liberal = prep_vars read_typ false true; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1114 |
val cert_vars_liberal = prep_vars cert_typ true true; |
8096 | 1115 |
|
10381 | 1116 |
end; |
1117 |
||
8096 | 1118 |
|
5819 | 1119 |
(* fix *) |
1120 |
||
8096 | 1121 |
local |
1122 |
||
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1123 |
fun map_fixes f = |
16540 | 1124 |
map_context (fn (syntax, (assumes, fixes), binds, thms, cases, defs) => |
1125 |
(syntax, (assumes, f fixes), binds, thms, cases, defs)); |
|
5819 | 1126 |
|
11925 | 1127 |
fun err_dups ctxt xs = raise CONTEXT ("Duplicate variable(s): " ^ commas_quote xs, ctxt); |
1128 |
||
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1129 |
val declare = |
16031
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1130 |
fold declare_term_syntax o |
fbf3471214d6
moved everything related to thms_containing to find_theorems.ML;
wenzelm
parents:
15979
diff
changeset
|
1131 |
List.mapPartial (fn (_, NONE) => NONE | (x, SOME T) => SOME (Free (x, T))); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1132 |
|
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1133 |
fun add_vars xs Ts ctxt = |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1134 |
let val xs' = Term.variantlist (map Syntax.skolem xs, map #2 (fixes_of ctxt)) in |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1135 |
ctxt |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1136 |
|> declare (xs' ~~ Ts) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1137 |
|> map_fixes (fn fixes => (xs ~~ xs') @ fixes) |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1138 |
end; |
11925 | 1139 |
|
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1140 |
fun add_vars_direct xs Ts ctxt = |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1141 |
ctxt |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1142 |
|> declare (xs ~~ Ts) |
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1143 |
|> map_fixes (fn fixes => |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1144 |
(case xs inter_string map #1 fixes of |
12309
03e9287be350
name space for local thms (export cond_extern, qualified);
wenzelm
parents:
12291
diff
changeset
|
1145 |
[] => (xs ~~ xs) @ fixes |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1146 |
| dups => err_dups ctxt dups)); |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1147 |
|
11925 | 1148 |
|
1149 |
fun gen_fix prep add raw_vars ctxt = |
|
8096 | 1150 |
let |
1151 |
val (ctxt', varss) = foldl_map prep (ctxt, raw_vars); |
|
15570 | 1152 |
val vars = rev (List.concat (map (fn (xs, T) => map (rpair T) xs) varss)); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1153 |
val xs = map #1 vars; |
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1154 |
val Ts = map #2 vars; |
8096 | 1155 |
in |
11925 | 1156 |
(case Library.duplicates xs of [] => () | dups => err_dups ctxt dups); |
12130
30d9143aff7e
syntactic declaration of external *and* internal versions of fixes;
wenzelm
parents:
12123
diff
changeset
|
1157 |
ctxt' |> add xs Ts |
8096 | 1158 |
end; |
5819 | 1159 |
|
15531 | 1160 |
fun prep_type (x, NONE, SOME mx) = ([x], SOME (mixfix_type mx)) |
12576
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
1161 |
| prep_type (x, opt_T, _) = ([x], opt_T); |
9fd10052c3f7
added add_fixes: derives mssing type scheme from mixfix;
wenzelm
parents:
12550
diff
changeset
|
1162 |
|
8096 | 1163 |
in |
7679 | 1164 |
|
11925 | 1165 |
val fix = gen_fix read_vars add_vars; |
1166 |
val fix_i = gen_fix cert_vars add_vars; |
|
14720
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1167 |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1168 |
fun fix_direct liberal = |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1169 |
gen_fix (if liberal then cert_vars_liberal else cert_vars) add_vars_direct; |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1170 |
|
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1171 |
fun add_fixes decls = add_syntax decls o fix_direct false (map prep_type decls); |
ceff6d4fb836
cleanup up read functions, include liberal versions;
wenzelm
parents:
14707
diff
changeset
|
1172 |
fun add_fixes_liberal decls = add_syntax decls o fix_direct true (map prep_type decls); |
8096 | 1173 |
|
1174 |
end; |
|
5819 | 1175 |
|
12048 | 1176 |
fun fix_frees ts ctxt = |
1177 |
let |
|
16861 | 1178 |
val frees = fold Term.add_frees ts []; |
15531 | 1179 |
fun new (x, T) = if is_fixed ctxt x then NONE else SOME ([x], SOME T); |
15570 | 1180 |
in fix_direct false (rev (List.mapPartial new frees)) ctxt end; |
12016 | 1181 |
|
6895 | 1182 |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1183 |
(*Note: improper use may result in variable capture / dynamic scoping!*) |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1184 |
fun bind_skolem ctxt xs = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1185 |
let |
15531 | 1186 |
val ctxt' = ctxt |> fix_i [(xs, NONE)]; |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1187 |
fun bind (t as Free (x, T)) = |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1188 |
if x mem_string xs then |
15531 | 1189 |
(case lookup_skolem ctxt' x of SOME x' => Free (x', T) | NONE => t) |
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1190 |
else t |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1191 |
| bind (t $ u) = bind t $ bind u |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1192 |
| bind (Abs (x, T, t)) = Abs (x, T, bind t) |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1193 |
| bind a = a; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1194 |
in bind end; |
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1195 |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1196 |
|
5819 | 1197 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1198 |
(** cases **) |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1199 |
|
16147 | 1200 |
fun apply_case ({fixes, assumes, binds}: RuleCases.T) ctxt = |
1201 |
let |
|
1202 |
fun bind (c, (x, T)) = (c |> fix_i [([x], SOME T)], bind_skolem c [x] (Free (x, T))); |
|
1203 |
val (ctxt', xs) = foldl_map bind (ctxt, fixes); |
|
1204 |
fun app t = Library.foldl Term.betapply (t, xs); |
|
1205 |
in (ctxt', (map (apsnd (Option.map app)) binds, map (apsnd (map app)) assumes)) end; |
|
1206 |
||
1207 |
local |
|
1208 |
||
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1209 |
fun prep_case ctxt name xs {fixes, assumes, binds} = |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1210 |
let |
15974 | 1211 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (if_none opt_x y, T) :: replace xs ys |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1212 |
| replace [] ys = ys |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1213 |
| replace (_ :: _) [] = raise CONTEXT ("Too many parameters for case " ^ quote name, ctxt); |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1214 |
in |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
1215 |
if null (foldr Term.add_typ_tvars [] (map snd fixes)) andalso |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
1216 |
null (foldr Term.add_term_vars [] (List.concat (map snd assumes))) then |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1217 |
{fixes = replace xs fixes, assumes = assumes, binds = map drop_schematic binds} |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1218 |
else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt) |
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11764
diff
changeset
|
1219 |
end; |
8403 | 1220 |
|
16668 | 1221 |
fun rem_case name = remove (fn (x: string, (y, _)) => x = y) name; |
16147 | 1222 |
|
1223 |
fun add_case ("", _) cases = cases |
|
1224 |
| add_case (name, NONE) cases = rem_case name cases |
|
1225 |
| add_case (name, SOME c) cases = (name, c) :: rem_case name cases; |
|
1226 |
||
1227 |
in |
|
1228 |
||
16540 | 1229 |
fun get_case ctxt name xs = |
1230 |
(case assoc_string (cases_of ctxt, name) of |
|
15531 | 1231 |
NONE => raise CONTEXT ("Unknown case: " ^ quote name, ctxt) |
1232 |
| SOME c => prep_case ctxt name xs c); |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1233 |
|
16540 | 1234 |
fun add_cases xs = map_context (fn (syntax, asms, binds, thms, cases, defs) => |
1235 |
(syntax, asms, binds, thms, fold add_case xs cases, defs)); |
|
8384 | 1236 |
|
16147 | 1237 |
end; |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1238 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1239 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1240 |
|
10810 | 1241 |
(** print context information **) |
1242 |
||
1243 |
val verbose = ref false; |
|
1244 |
fun verb f x = if ! verbose then f (x ()) else []; |
|
1245 |
fun verb_single x = verb Library.single x; |
|
1246 |
||
1247 |
fun setmp_verbose f x = Library.setmp verbose true f x; |
|
1248 |
||
1249 |
fun pretty_items prt name items = |
|
1250 |
let |
|
1251 |
fun prt_itms (name, [x]) = Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt x] |
|
1252 |
| prt_itms (name, xs) = Pretty.big_list (name ^ ":") (map prt xs); |
|
1253 |
in |
|
1254 |
if null items andalso not (! verbose) then [] |
|
1255 |
else [Pretty.big_list name (map prt_itms items)] |
|
1256 |
end; |
|
1257 |
||
1258 |
||
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1259 |
(* local syntax *) |
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1260 |
|
12093 | 1261 |
val print_syntax = Syntax.print_syntax o syn_of; |
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1262 |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1263 |
|
10810 | 1264 |
(* term bindings *) |
1265 |
||
16540 | 1266 |
fun pretty_binds ctxt = |
10810 | 1267 |
let |
16540 | 1268 |
val binds = binds_of ctxt; |
12057 | 1269 |
fun prt_bind (xi, (t, T)) = pretty_term ctxt (Logic.mk_equals (Var (xi, T), t)); |
10810 | 1270 |
in |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1271 |
if Vartab.is_empty binds andalso not (! verbose) then [] |
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1272 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
10810 | 1273 |
end; |
1274 |
||
1275 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1276 |
||
1277 |
||
1278 |
(* local theorems *) |
|
1279 |
||
16540 | 1280 |
fun pretty_lthms ctxt = |
1281 |
pretty_items (pretty_thm ctxt) "facts:" (NameSpace.extern_table (#2 (thms_of ctxt))); |
|
10810 | 1282 |
|
12057 | 1283 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
10810 | 1284 |
|
1285 |
||
1286 |
(* local contexts *) |
|
1287 |
||
16540 | 1288 |
fun pretty_cases ctxt = |
10810 | 1289 |
let |
12057 | 1290 |
val prt_term = pretty_term ctxt; |
1291 |
||
10810 | 1292 |
fun prt_let (xi, t) = Pretty.block |
10818 | 1293 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
10810 | 1294 |
Pretty.quote (prt_term t)]; |
1295 |
||
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1296 |
fun prt_asm (a, ts) = Pretty.block (Pretty.breaks |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1297 |
((if a = "" then [] else [Pretty.str (a ^ ":")]) @ map (Pretty.quote o prt_term) ts)); |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1298 |
|
10810 | 1299 |
fun prt_sect _ _ _ [] = [] |
1300 |
| prt_sect s sep prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: |
|
15570 | 1301 |
List.concat (Library.separate sep (map (Library.single o prt) xs))))]; |
10810 | 1302 |
|
10830 | 1303 |
fun prt_case (name, (fixes, (lets, asms))) = Pretty.block (Pretty.fbreaks |
10810 | 1304 |
(Pretty.str (name ^ ":") :: |
11915 | 1305 |
prt_sect "fix" [] (Pretty.str o fst) fixes @ |
10810 | 1306 |
prt_sect "let" [Pretty.str "and"] prt_let |
15570 | 1307 |
(List.mapPartial (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @ |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1308 |
(if forall (null o #2) asms then [] |
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1309 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms))); |
16540 | 1310 |
|
1311 |
val cases = cases_of ctxt; |
|
10810 | 1312 |
in |
1313 |
if null cases andalso not (! verbose) then [] |
|
10830 | 1314 |
else [Pretty.big_list "cases:" |
16147 | 1315 |
(map (prt_case o apsnd (fn c => (#fixes c, #2 (apply_case c ctxt)))) (rev cases))] |
10810 | 1316 |
end; |
1317 |
||
1318 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1319 |
||
1320 |
||
12057 | 1321 |
(* core context *) |
10810 | 1322 |
|
1323 |
val prems_limit = ref 10; |
|
1324 |
||
12057 | 1325 |
fun pretty_asms ctxt = |
10810 | 1326 |
let |
12057 | 1327 |
val prt_term = pretty_term ctxt; |
1328 |
||
12093 | 1329 |
(*structures*) |
1330 |
val (_, structs, _) = syntax_of ctxt; |
|
1331 |
val prt_structs = if null structs then [] |
|
1332 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
|
1333 |
Pretty.commas (map Pretty.str structs))]; |
|
1334 |
||
12057 | 1335 |
(*fixes*) |
1336 |
fun prt_fix (x, x') = |
|
1337 |
if x = x' then Pretty.str x |
|
1338 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
12093 | 1339 |
val fixes = rev (filter_out |
1340 |
((can Syntax.dest_internal o #1) orf (fn (_, x') => x' mem_string structs)) (fixes_of ctxt)); |
|
1341 |
val prt_fixes = if null fixes then [] |
|
1342 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
|
1343 |
Pretty.commas (map prt_fix fixes))]; |
|
12057 | 1344 |
|
1345 |
(*prems*) |
|
10810 | 1346 |
val limit = ! prems_limit; |
1347 |
val prems = prems_of ctxt; |
|
1348 |
val len = length prems; |
|
12093 | 1349 |
val prt_prems = if null prems then [] |
1350 |
else [Pretty.big_list "prems:" ((if len <= limit then [] else [Pretty.str "..."]) @ |
|
1351 |
map (pretty_thm ctxt) (Library.drop (len - limit, prems)))]; |
|
1352 |
||
1353 |
in prt_structs @ prt_fixes @ prt_prems end; |
|
10810 | 1354 |
|
1355 |
||
1356 |
(* main context *) |
|
1357 |
||
16540 | 1358 |
fun pretty_context ctxt = |
10810 | 1359 |
let |
12057 | 1360 |
val prt_term = pretty_term ctxt; |
1361 |
val prt_typ = pretty_typ ctxt; |
|
1362 |
val prt_sort = pretty_sort ctxt; |
|
10810 | 1363 |
|
1364 |
(*theory*) |
|
12057 | 1365 |
val pretty_thy = Pretty.block |
16458 | 1366 |
[Pretty.str "Theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
10810 | 1367 |
|
1368 |
(*defaults*) |
|
1369 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1370 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1371 |
||
1372 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1373 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1374 |
||
1375 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1376 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1377 |
||
1378 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1379 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
16540 | 1380 |
|
1381 |
val (types, sorts, used, _) = defaults_of ctxt; |
|
10810 | 1382 |
in |
1383 |
verb_single (K pretty_thy) @ |
|
12057 | 1384 |
pretty_asms ctxt @ |
10810 | 1385 |
verb pretty_binds (K ctxt) @ |
12057 | 1386 |
verb pretty_lthms (K ctxt) @ |
10810 | 1387 |
verb pretty_cases (K ctxt) @ |
1388 |
verb_single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
|
1389 |
verb_single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) @ |
|
1390 |
verb_single (fn () => Pretty.strs ("used type variable names:" :: used)) |
|
1391 |
end; |
|
1392 |
||
5819 | 1393 |
end; |