author | schirmer |
Mon, 12 May 2003 14:16:38 +0200 | |
changeset 14010 | 32faa7e2e767 |
parent 13665 | 66e151df01c8 |
child 14472 | cba7c0a3ffb3 |
permissions | -rw-r--r-- |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1 |
(* Title: Pure/term.ML |
0 | 2 |
ID: $Id$ |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright Cambridge University 1992 |
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
5 |
|
4444 | 6 |
Simply typed lambda-calculus: types, terms, and basic operations. |
0 | 7 |
*) |
8 |
||
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
9 |
infix 9 $; |
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
10 |
infixr 5 -->; |
4444 | 11 |
infixr --->; |
12 |
infix aconv; |
|
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
13 |
|
4444 | 14 |
signature BASIC_TERM = |
15 |
sig |
|
16 |
type indexname |
|
17 |
type class |
|
18 |
type sort |
|
19 |
datatype typ = |
|
20 |
Type of string * typ list | |
|
21 |
TFree of string * sort | |
|
22 |
TVar of indexname * sort |
|
23 |
val --> : typ * typ -> typ |
|
24 |
val ---> : typ list * typ -> typ |
|
25 |
val is_TVar: typ -> bool |
|
26 |
val domain_type: typ -> typ |
|
4480 | 27 |
val range_type: typ -> typ |
4444 | 28 |
val binder_types: typ -> typ list |
29 |
val body_type: typ -> typ |
|
30 |
val strip_type: typ -> typ list * typ |
|
31 |
datatype term = |
|
32 |
Const of string * typ | |
|
33 |
Free of string * typ | |
|
34 |
Var of indexname * typ | |
|
35 |
Bound of int | |
|
36 |
Abs of string * typ * term | |
|
4493 | 37 |
$ of term * term |
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
38 |
structure Vartab : TABLE |
13000 | 39 |
structure Typtab : TABLE |
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
40 |
structure Termtab : TABLE |
4444 | 41 |
exception TYPE of string * typ list * term list |
42 |
exception TERM of string * term list |
|
7318 | 43 |
val is_Bound: term -> bool |
4444 | 44 |
val is_Const: term -> bool |
45 |
val is_Free: term -> bool |
|
46 |
val is_Var: term -> bool |
|
6033
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
47 |
val dest_Type: typ -> string * typ list |
4444 | 48 |
val dest_Const: term -> string * typ |
49 |
val dest_Free: term -> string * typ |
|
50 |
val dest_Var: term -> indexname * typ |
|
51 |
val type_of: term -> typ |
|
52 |
val type_of1: typ list * term -> typ |
|
53 |
val fastype_of: term -> typ |
|
54 |
val fastype_of1: typ list * term -> typ |
|
10806 | 55 |
val list_abs: (string * typ) list * term -> term |
4444 | 56 |
val strip_abs_body: term -> term |
57 |
val strip_abs_vars: term -> (string * typ) list |
|
58 |
val strip_qnt_body: string -> term -> term |
|
59 |
val strip_qnt_vars: string -> term -> (string * typ) list |
|
60 |
val list_comb: term * term list -> term |
|
61 |
val strip_comb: term -> term * term list |
|
62 |
val head_of: term -> term |
|
63 |
val size_of_term: term -> int |
|
64 |
val map_type_tvar: (indexname * sort -> typ) -> typ -> typ |
|
65 |
val map_type_tfree: (string * sort -> typ) -> typ -> typ |
|
66 |
val map_term_types: (typ -> typ) -> term -> term |
|
67 |
val it_term_types: (typ * 'a -> 'a) -> term * 'a -> 'a |
|
68 |
val map_typ: (class -> class) -> (string -> string) -> typ -> typ |
|
69 |
val map_term: |
|
70 |
(class -> class) -> |
|
71 |
(string -> string) -> (string -> string) -> term -> term |
|
72 |
val foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a |
|
8609 | 73 |
val foldl_term_types: (term -> 'a * typ -> 'a) -> 'a * term -> 'a |
4444 | 74 |
val foldl_types: ('a * typ -> 'a) -> 'a * term -> 'a |
75 |
val foldl_aterms: ('a * term -> 'a) -> 'a * term -> 'a |
|
6548
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
76 |
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term |
4444 | 77 |
val dummyT: typ |
78 |
val logicC: class |
|
79 |
val logicS: sort |
|
80 |
val itselfT: typ -> typ |
|
81 |
val a_itselfT: typ |
|
82 |
val propT: typ |
|
83 |
val implies: term |
|
84 |
val all: typ -> term |
|
85 |
val equals: typ -> term |
|
86 |
val strip_all_body: term -> term |
|
87 |
val strip_all_vars: term -> (string * typ) list |
|
88 |
val incr_bv: int * int * term -> term |
|
89 |
val incr_boundvars: int -> term -> term |
|
90 |
val add_loose_bnos: term * int * int list -> int list |
|
91 |
val loose_bnos: term -> int list |
|
92 |
val loose_bvar: term * int -> bool |
|
93 |
val loose_bvar1: term * int -> bool |
|
94 |
val subst_bounds: term list * term -> term |
|
95 |
val subst_bound: term * term -> term |
|
96 |
val subst_TVars: (indexname * typ) list -> term -> term |
|
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
97 |
val subst_TVars_Vartab: typ Vartab.table -> term -> term |
4444 | 98 |
val betapply: term * term -> term |
99 |
val eq_ix: indexname * indexname -> bool |
|
100 |
val ins_ix: indexname * indexname list -> indexname list |
|
101 |
val mem_ix: indexname * indexname list -> bool |
|
102 |
val eq_sort: sort * class list -> bool |
|
103 |
val mem_sort: sort * class list list -> bool |
|
104 |
val subset_sort: sort list * class list list -> bool |
|
105 |
val eq_set_sort: sort list * sort list -> bool |
|
106 |
val ins_sort: sort * class list list -> class list list |
|
107 |
val union_sort: sort list * sort list -> sort list |
|
7638 | 108 |
val rems_sort: sort list * sort list -> sort list |
4444 | 109 |
val aconv: term * term -> bool |
110 |
val aconvs: term list * term list -> bool |
|
111 |
val mem_term: term * term list -> bool |
|
112 |
val subset_term: term list * term list -> bool |
|
113 |
val eq_set_term: term list * term list -> bool |
|
114 |
val ins_term: term * term list -> term list |
|
115 |
val union_term: term list * term list -> term list |
|
5585 | 116 |
val inter_term: term list * term list -> term list |
4444 | 117 |
val could_unify: term * term -> bool |
118 |
val subst_free: (term * term) list -> term -> term |
|
119 |
val subst_atomic: (term * term) list -> term -> term |
|
120 |
val subst_vars: (indexname * typ) list * (indexname * term) list -> term -> term |
|
121 |
val typ_subst_TVars: (indexname * typ) list -> typ -> typ |
|
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
122 |
val typ_subst_TVars_Vartab : typ Vartab.table -> typ -> typ |
4444 | 123 |
val subst_Vars: (indexname * term) list -> term -> term |
124 |
val incr_tvar: int -> typ -> typ |
|
125 |
val xless: (string * int) * indexname -> bool |
|
126 |
val atless: term * term -> bool |
|
127 |
val insert_aterm: term * term list -> term list |
|
128 |
val abstract_over: term * term -> term |
|
11922 | 129 |
val lambda: term -> term -> term |
4444 | 130 |
val absfree: string * typ * term -> term |
131 |
val list_abs_free: (string * typ) list * term -> term |
|
132 |
val list_all_free: (string * typ) list * term -> term |
|
133 |
val list_all: (string * typ) list * term -> term |
|
134 |
val maxidx_of_typ: typ -> int |
|
135 |
val maxidx_of_typs: typ list -> int |
|
136 |
val maxidx_of_term: term -> int |
|
13665 | 137 |
val maxidx_of_terms: term list -> int |
4694 | 138 |
val read_radixint: int * string list -> int * string list |
139 |
val read_int: string list -> int * string list |
|
5986 | 140 |
val oct_char: string -> string |
4444 | 141 |
val variant: string list -> string -> string |
142 |
val variantlist: string list * string list -> string list |
|
143 |
val variant_abs: string * typ * term -> string * term |
|
144 |
val rename_wrt_term: term -> (string * typ) list -> (string * typ) list |
|
145 |
val add_new_id: string list * string -> string list |
|
146 |
val add_typ_classes: typ * class list -> class list |
|
147 |
val add_typ_ixns: indexname list * typ -> indexname list |
|
148 |
val add_typ_tfree_names: typ * string list -> string list |
|
149 |
val add_typ_tfrees: typ * (string * sort) list -> (string * sort) list |
|
150 |
val typ_tfrees: typ -> (string * sort) list |
|
151 |
val add_typ_tvars: typ * (indexname * sort) list -> (indexname * sort) list |
|
152 |
val typ_tvars: typ -> (indexname * sort) list |
|
153 |
val add_typ_tycons: typ * string list -> string list |
|
154 |
val add_typ_varnames: typ * string list -> string list |
|
155 |
val add_term_classes: term * class list -> class list |
|
156 |
val add_term_consts: term * string list -> string list |
|
13646 | 157 |
val term_consts: term -> string list |
4444 | 158 |
val add_term_frees: term * term list -> term list |
159 |
val term_frees: term -> term list |
|
12802
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
160 |
val add_term_free_names: term * string list -> string list |
4444 | 161 |
val add_term_names: term * string list -> string list |
162 |
val add_term_tfree_names: term * string list -> string list |
|
163 |
val add_term_tfrees: term * (string * sort) list -> (string * sort) list |
|
164 |
val term_tfrees: term -> (string * sort) list |
|
165 |
val add_term_tvar_ixns: term * indexname list -> indexname list |
|
166 |
val add_term_tvarnames: term * string list -> string list |
|
167 |
val add_term_tvars: term * (indexname * sort) list -> (indexname * sort) list |
|
168 |
val term_tvars: term -> (indexname * sort) list |
|
169 |
val add_term_tycons: term * string list -> string list |
|
170 |
val add_term_vars: term * term list -> term list |
|
171 |
val term_vars: term -> term list |
|
172 |
val exists_Const: (string * typ -> bool) -> term -> bool |
|
4631 | 173 |
val exists_subterm: (term -> bool) -> term -> bool |
4444 | 174 |
val compress_type: typ -> typ |
175 |
val compress_term: term -> term |
|
176 |
end; |
|
0 | 177 |
|
4444 | 178 |
signature TERM = |
179 |
sig |
|
180 |
include BASIC_TERM |
|
12981 | 181 |
val match_bvars: (term * term) * (string * string) list -> (string * string) list |
182 |
val rename_abs: term -> term -> term -> term option |
|
12499 | 183 |
val invent_names: string list -> string -> int -> string list |
184 |
val invent_type_names: string list -> int -> string list |
|
185 |
val add_tvarsT: (indexname * sort) list * typ -> (indexname * sort) list |
|
186 |
val add_tvars: (indexname * sort) list * term -> (indexname * sort) list |
|
187 |
val add_vars: (indexname * typ) list * term -> (indexname * typ) list |
|
188 |
val add_frees: (string * typ) list * term -> (string * typ) list |
|
4444 | 189 |
val indexname_ord: indexname * indexname -> order |
190 |
val typ_ord: typ * typ -> order |
|
191 |
val typs_ord: typ list * typ list -> order |
|
192 |
val term_ord: term * term -> order |
|
193 |
val terms_ord: term list * term list -> order |
|
194 |
val termless: term * term -> bool |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
195 |
val dummy_patternN: string |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
196 |
val no_dummy_patterns: term -> term |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
197 |
val replace_dummy_patterns: int * term -> int * term |
10552 | 198 |
val is_replaced_dummy_pattern: indexname -> bool |
13484 | 199 |
val adhoc_freeze_vars: term -> term * string list |
4444 | 200 |
end; |
201 |
||
202 |
structure Term: TERM = |
|
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
203 |
struct |
0 | 204 |
|
205 |
(*Indexnames can be quickly renamed by adding an offset to the integer part, |
|
206 |
for resolution.*) |
|
207 |
type indexname = string*int; |
|
208 |
||
4626 | 209 |
(* Types are classified by sorts. *) |
0 | 210 |
type class = string; |
211 |
type sort = class list; |
|
212 |
||
213 |
(* The sorts attached to TFrees and TVars specify the sort of that variable *) |
|
214 |
datatype typ = Type of string * typ list |
|
215 |
| TFree of string * sort |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
216 |
| TVar of indexname * sort; |
0 | 217 |
|
6033
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
218 |
(*Terms. Bound variables are indicated by depth number. |
0 | 219 |
Free variables, (scheme) variables and constants have names. |
4626 | 220 |
An term is "closed" if every bound variable of level "lev" |
13000 | 221 |
is enclosed by at least "lev" abstractions. |
0 | 222 |
|
223 |
It is possible to create meaningless terms containing loose bound vars |
|
224 |
or type mismatches. But such terms are not allowed in rules. *) |
|
225 |
||
226 |
||
227 |
||
13000 | 228 |
datatype term = |
0 | 229 |
Const of string * typ |
13000 | 230 |
| Free of string * typ |
0 | 231 |
| Var of indexname * typ |
232 |
| Bound of int |
|
233 |
| Abs of string*typ*term |
|
3965 | 234 |
| op $ of term*term; |
0 | 235 |
|
236 |
||
237 |
(*For errors involving type mismatches*) |
|
238 |
exception TYPE of string * typ list * term list; |
|
239 |
||
240 |
(*For system errors involving terms*) |
|
241 |
exception TERM of string * term list; |
|
242 |
||
243 |
||
244 |
(*Note variable naming conventions! |
|
245 |
a,b,c: string |
|
246 |
f,g,h: functions (including terms of function type) |
|
247 |
i,j,m,n: int |
|
248 |
t,u: term |
|
249 |
v,w: indexnames |
|
250 |
x,y: any |
|
251 |
A,B,C: term (denoting formulae) |
|
252 |
T,U: typ |
|
253 |
*) |
|
254 |
||
255 |
||
6033
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
256 |
(** Types **) |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
257 |
|
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
258 |
fun S --> T = Type("fun",[S,T]); |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
259 |
|
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
260 |
(*handy for multiple args: [T1,...,Tn]--->T gives T1-->(T2--> ... -->T)*) |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
261 |
val op ---> = foldr (op -->); |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
262 |
|
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
263 |
fun dest_Type (Type x) = x |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
264 |
| dest_Type T = raise TYPE ("dest_Type", [T], []); |
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
265 |
|
c8c69a4a7762
moved dest_Type to term.ML from HOL/Tools/primrec_package
paulson
parents:
5986
diff
changeset
|
266 |
|
0 | 267 |
(** Discriminators **) |
268 |
||
7318 | 269 |
fun is_Bound (Bound _) = true |
270 |
| is_Bound _ = false; |
|
271 |
||
0 | 272 |
fun is_Const (Const _) = true |
273 |
| is_Const _ = false; |
|
274 |
||
275 |
fun is_Free (Free _) = true |
|
276 |
| is_Free _ = false; |
|
277 |
||
278 |
fun is_Var (Var _) = true |
|
279 |
| is_Var _ = false; |
|
280 |
||
281 |
fun is_TVar (TVar _) = true |
|
282 |
| is_TVar _ = false; |
|
283 |
||
284 |
(** Destructors **) |
|
285 |
||
286 |
fun dest_Const (Const x) = x |
|
287 |
| dest_Const t = raise TERM("dest_Const", [t]); |
|
288 |
||
289 |
fun dest_Free (Free x) = x |
|
290 |
| dest_Free t = raise TERM("dest_Free", [t]); |
|
291 |
||
292 |
fun dest_Var (Var x) = x |
|
293 |
| dest_Var t = raise TERM("dest_Var", [t]); |
|
294 |
||
295 |
||
4464 | 296 |
fun domain_type (Type("fun", [T,_])) = T |
297 |
and range_type (Type("fun", [_,T])) = T; |
|
4064 | 298 |
|
0 | 299 |
(* maps [T1,...,Tn]--->T to the list [T1,T2,...,Tn]*) |
300 |
fun binder_types (Type("fun",[S,T])) = S :: binder_types T |
|
301 |
| binder_types _ = []; |
|
302 |
||
303 |
(* maps [T1,...,Tn]--->T to T*) |
|
304 |
fun body_type (Type("fun",[S,T])) = body_type T |
|
305 |
| body_type T = T; |
|
306 |
||
307 |
(* maps [T1,...,Tn]--->T to ([T1,T2,...,Tn], T) *) |
|
308 |
fun strip_type T : typ list * typ = |
|
309 |
(binder_types T, body_type T); |
|
310 |
||
311 |
||
312 |
(*Compute the type of the term, checking that combinations are well-typed |
|
313 |
Ts = [T0,T1,...] holds types of bound variables 0, 1, ...*) |
|
314 |
fun type_of1 (Ts, Const (_,T)) = T |
|
315 |
| type_of1 (Ts, Free (_,T)) = T |
|
13000 | 316 |
| type_of1 (Ts, Bound i) = (nth_elem (i,Ts) |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
317 |
handle LIST _ => raise TYPE("type_of: bound variable", [], [Bound i])) |
0 | 318 |
| type_of1 (Ts, Var (_,T)) = T |
319 |
| type_of1 (Ts, Abs (_,T,body)) = T --> type_of1(T::Ts, body) |
|
13000 | 320 |
| type_of1 (Ts, f$u) = |
0 | 321 |
let val U = type_of1(Ts,u) |
322 |
and T = type_of1(Ts,f) |
|
323 |
in case T of |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
324 |
Type("fun",[T1,T2]) => |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
325 |
if T1=U then T2 else raise TYPE |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
326 |
("type_of: type mismatch in application", [T1,U], [f$u]) |
13000 | 327 |
| _ => raise TYPE |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
328 |
("type_of: function type is expected in application", |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
329 |
[T,U], [f$u]) |
0 | 330 |
end; |
331 |
||
332 |
fun type_of t : typ = type_of1 ([],t); |
|
333 |
||
334 |
(*Determines the type of a term, with minimal checking*) |
|
13000 | 335 |
fun fastype_of1 (Ts, f$u) = |
61 | 336 |
(case fastype_of1 (Ts,f) of |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
337 |
Type("fun",[_,T]) => T |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
338 |
| _ => raise TERM("fastype_of: expected function type", [f$u])) |
61 | 339 |
| fastype_of1 (_, Const (_,T)) = T |
340 |
| fastype_of1 (_, Free (_,T)) = T |
|
341 |
| fastype_of1 (Ts, Bound i) = (nth_elem(i,Ts) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
342 |
handle LIST _ => raise TERM("fastype_of: Bound", [Bound i])) |
13000 | 343 |
| fastype_of1 (_, Var (_,T)) = T |
61 | 344 |
| fastype_of1 (Ts, Abs (_,T,u)) = T --> fastype_of1 (T::Ts, u); |
345 |
||
346 |
fun fastype_of t : typ = fastype_of1 ([],t); |
|
0 | 347 |
|
348 |
||
10806 | 349 |
val list_abs = foldr (fn ((x, T), t) => Abs (x, T, t)); |
350 |
||
0 | 351 |
(* maps (x1,...,xn)t to t *) |
13000 | 352 |
fun strip_abs_body (Abs(_,_,t)) = strip_abs_body t |
0 | 353 |
| strip_abs_body u = u; |
354 |
||
355 |
(* maps (x1,...,xn)t to [x1, ..., xn] *) |
|
13000 | 356 |
fun strip_abs_vars (Abs(a,T,t)) = (a,T) :: strip_abs_vars t |
0 | 357 |
| strip_abs_vars u = [] : (string*typ) list; |
358 |
||
359 |
||
360 |
fun strip_qnt_body qnt = |
|
361 |
let fun strip(tm as Const(c,_)$Abs(_,_,t)) = if c=qnt then strip t else tm |
|
362 |
| strip t = t |
|
363 |
in strip end; |
|
364 |
||
365 |
fun strip_qnt_vars qnt = |
|
366 |
let fun strip(Const(c,_)$Abs(a,T,t)) = if c=qnt then (a,T)::strip t else [] |
|
367 |
| strip t = [] : (string*typ) list |
|
368 |
in strip end; |
|
369 |
||
370 |
||
371 |
(* maps (f, [t1,...,tn]) to f(t1,...,tn) *) |
|
372 |
val list_comb : term * term list -> term = foldl (op $); |
|
373 |
||
374 |
||
375 |
(* maps f(t1,...,tn) to (f, [t1,...,tn]) ; naturally tail-recursive*) |
|
13000 | 376 |
fun strip_comb u : term * term list = |
0 | 377 |
let fun stripc (f$t, ts) = stripc (f, t::ts) |
13000 | 378 |
| stripc x = x |
0 | 379 |
in stripc(u,[]) end; |
380 |
||
381 |
||
382 |
(* maps f(t1,...,tn) to f , which is never a combination *) |
|
383 |
fun head_of (f$t) = head_of f |
|
384 |
| head_of u = u; |
|
385 |
||
386 |
||
387 |
(*Number of atoms and abstractions in a term*) |
|
388 |
fun size_of_term (Abs (_,_,body)) = 1 + size_of_term body |
|
389 |
| size_of_term (f$t) = size_of_term f + size_of_term t |
|
390 |
| size_of_term _ = 1; |
|
391 |
||
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
392 |
fun map_type_tvar f (Type(a,Ts)) = Type(a, map (map_type_tvar f) Ts) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
393 |
| map_type_tvar f (T as TFree _) = T |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
394 |
| map_type_tvar f (TVar x) = f x; |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
395 |
|
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
396 |
fun map_type_tfree f (Type(a,Ts)) = Type(a, map (map_type_tfree f) Ts) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
397 |
| map_type_tfree f (TFree x) = f x |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
398 |
| map_type_tfree f (T as TVar _) = T; |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
399 |
|
0 | 400 |
(* apply a function to all types in a term *) |
401 |
fun map_term_types f = |
|
402 |
let fun map(Const(a,T)) = Const(a, f T) |
|
403 |
| map(Free(a,T)) = Free(a, f T) |
|
404 |
| map(Var(v,T)) = Var(v, f T) |
|
405 |
| map(t as Bound _) = t |
|
406 |
| map(Abs(a,T,t)) = Abs(a, f T, map t) |
|
407 |
| map(f$t) = map f $ map t; |
|
408 |
in map end; |
|
409 |
||
410 |
(* iterate a function over all types in a term *) |
|
411 |
fun it_term_types f = |
|
412 |
let fun iter(Const(_,T), a) = f(T,a) |
|
413 |
| iter(Free(_,T), a) = f(T,a) |
|
414 |
| iter(Var(_,T), a) = f(T,a) |
|
415 |
| iter(Abs(_,T,t), a) = iter(t,f(T,a)) |
|
416 |
| iter(f$u, a) = iter(f, iter(u, a)) |
|
417 |
| iter(Bound _, a) = a |
|
418 |
in iter end |
|
419 |
||
420 |
||
421 |
(** Connectives of higher order logic **) |
|
422 |
||
375 | 423 |
val logicC: class = "logic"; |
424 |
val logicS: sort = [logicC]; |
|
425 |
||
426 |
fun itselfT ty = Type ("itself", [ty]); |
|
427 |
val a_itselfT = itselfT (TFree ("'a", logicS)); |
|
428 |
||
0 | 429 |
val propT : typ = Type("prop",[]); |
430 |
||
431 |
val implies = Const("==>", propT-->propT-->propT); |
|
432 |
||
433 |
fun all T = Const("all", (T-->propT)-->propT); |
|
434 |
||
435 |
fun equals T = Const("==", T-->T-->propT); |
|
436 |
||
437 |
(* maps !!x1...xn. t to t *) |
|
13000 | 438 |
fun strip_all_body (Const("all",_)$Abs(_,_,t)) = strip_all_body t |
0 | 439 |
| strip_all_body t = t; |
440 |
||
441 |
(* maps !!x1...xn. t to [x1, ..., xn] *) |
|
442 |
fun strip_all_vars (Const("all",_)$Abs(a,T,t)) = |
|
13000 | 443 |
(a,T) :: strip_all_vars t |
0 | 444 |
| strip_all_vars t = [] : (string*typ) list; |
445 |
||
446 |
(*increments a term's non-local bound variables |
|
447 |
required when moving a term within abstractions |
|
448 |
inc is increment for bound variables |
|
449 |
lev is level at which a bound variable is considered 'loose'*) |
|
13000 | 450 |
fun incr_bv (inc, lev, u as Bound i) = if i>=lev then Bound(i+inc) else u |
0 | 451 |
| incr_bv (inc, lev, Abs(a,T,body)) = |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
452 |
Abs(a, T, incr_bv(inc,lev+1,body)) |
13000 | 453 |
| incr_bv (inc, lev, f$t) = |
0 | 454 |
incr_bv(inc,lev,f) $ incr_bv(inc,lev,t) |
455 |
| incr_bv (inc, lev, u) = u; |
|
456 |
||
457 |
fun incr_boundvars 0 t = t |
|
458 |
| incr_boundvars inc t = incr_bv(inc,0,t); |
|
459 |
||
12981 | 460 |
(*Scan a pair of terms; while they are similar, |
461 |
accumulate corresponding bound vars in "al"*) |
|
462 |
fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) = |
|
463 |
match_bvs(s, t, if x="" orelse y="" then al |
|
464 |
else (x,y)::al) |
|
465 |
| match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al)) |
|
466 |
| match_bvs(_,_,al) = al; |
|
467 |
||
468 |
(* strip abstractions created by parameters *) |
|
469 |
fun match_bvars((s,t),al) = match_bvs(strip_abs_body s, strip_abs_body t, al); |
|
470 |
||
471 |
fun rename_abs pat obj t = |
|
472 |
let |
|
473 |
val ren = match_bvs (pat, obj, []); |
|
474 |
fun ren_abs (Abs (x, T, b)) = |
|
475 |
Abs (if_none (assoc_string (ren, x)) x, T, ren_abs b) |
|
476 |
| ren_abs (f $ t) = ren_abs f $ ren_abs t |
|
477 |
| ren_abs t = t |
|
478 |
in if null ren then None else Some (ren_abs t) end; |
|
0 | 479 |
|
480 |
(*Accumulate all 'loose' bound vars referring to level 'lev' or beyond. |
|
481 |
(Bound 0) is loose at level 0 *) |
|
13000 | 482 |
fun add_loose_bnos (Bound i, lev, js) = |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
483 |
if i<lev then js else (i-lev) ins_int js |
0 | 484 |
| add_loose_bnos (Abs (_,_,t), lev, js) = add_loose_bnos (t, lev+1, js) |
485 |
| add_loose_bnos (f$t, lev, js) = |
|
13000 | 486 |
add_loose_bnos (f, lev, add_loose_bnos (t, lev, js)) |
0 | 487 |
| add_loose_bnos (_, _, js) = js; |
488 |
||
489 |
fun loose_bnos t = add_loose_bnos (t, 0, []); |
|
490 |
||
491 |
(* loose_bvar(t,k) iff t contains a 'loose' bound variable referring to |
|
492 |
level k or beyond. *) |
|
493 |
fun loose_bvar(Bound i,k) = i >= k |
|
494 |
| loose_bvar(f$t, k) = loose_bvar(f,k) orelse loose_bvar(t,k) |
|
495 |
| loose_bvar(Abs(_,_,t),k) = loose_bvar(t,k+1) |
|
496 |
| loose_bvar _ = false; |
|
497 |
||
2792 | 498 |
fun loose_bvar1(Bound i,k) = i = k |
499 |
| loose_bvar1(f$t, k) = loose_bvar1(f,k) orelse loose_bvar1(t,k) |
|
500 |
| loose_bvar1(Abs(_,_,t),k) = loose_bvar1(t,k+1) |
|
501 |
| loose_bvar1 _ = false; |
|
0 | 502 |
|
503 |
(*Substitute arguments for loose bound variables. |
|
504 |
Beta-reduction of arg(n-1)...arg0 into t replacing (Bound i) with (argi). |
|
4626 | 505 |
Note that for ((%x y. c) a b), the bound vars in c are x=1 and y=0 |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
506 |
and the appropriate call is subst_bounds([b,a], c) . |
0 | 507 |
Loose bound variables >=n are reduced by "n" to |
508 |
compensate for the disappearance of lambdas. |
|
509 |
*) |
|
13000 | 510 |
fun subst_bounds (args: term list, t) : term = |
0 | 511 |
let val n = length args; |
512 |
fun subst (t as Bound i, lev) = |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
513 |
(if i<lev then t (*var is locally bound*) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
514 |
else incr_boundvars lev (List.nth(args, i-lev)) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
515 |
handle Subscript => Bound(i-n) (*loose: change it*)) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
516 |
| subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1)) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
517 |
| subst (f$t, lev) = subst(f,lev) $ subst(t,lev) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
518 |
| subst (t,lev) = t |
0 | 519 |
in case args of [] => t | _ => subst (t,0) end; |
520 |
||
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
521 |
(*Special case: one argument*) |
13000 | 522 |
fun subst_bound (arg, t) : term = |
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
523 |
let fun subst (t as Bound i, lev) = |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
524 |
if i<lev then t (*var is locally bound*) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
525 |
else if i=lev then incr_boundvars lev arg |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
526 |
else Bound(i-1) (*loose: change it*) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
527 |
| subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1)) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
528 |
| subst (f$t, lev) = subst(f,lev) $ subst(t,lev) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
529 |
| subst (t,lev) = t |
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
530 |
in subst (t,0) end; |
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
531 |
|
0 | 532 |
(*beta-reduce if possible, else form application*) |
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
533 |
fun betapply (Abs(_,_,t), u) = subst_bound (u,t) |
0 | 534 |
| betapply (f,u) = f$u; |
535 |
||
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
536 |
(** Equality, membership and insertion of indexnames (string*ints) **) |
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
537 |
|
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
538 |
(*optimized equality test for indexnames. Yields a huge gain under Poly/ML*) |
2959 | 539 |
fun eq_ix ((a, i):indexname, (a',i'):indexname) = (a=a') andalso i=i'; |
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
540 |
|
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
541 |
(*membership in a list, optimized version for indexnames*) |
2959 | 542 |
fun mem_ix (_, []) = false |
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
543 |
| mem_ix (x, y :: ys) = eq_ix(x,y) orelse mem_ix (x, ys); |
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
544 |
|
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
545 |
(*insertion into list, optimized version for indexnames*) |
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
546 |
fun ins_ix (x,xs) = if mem_ix (x, xs) then xs else x :: xs; |
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
547 |
|
0 | 548 |
(*Tests whether 2 terms are alpha-convertible and have same type. |
4626 | 549 |
Note that constants may have more than one type.*) |
0 | 550 |
fun (Const(a,T)) aconv (Const(b,U)) = a=b andalso T=U |
2752 | 551 |
| (Free(a,T)) aconv (Free(b,U)) = a=b andalso T=U |
552 |
| (Var(v,T)) aconv (Var(w,U)) = eq_ix(v,w) andalso T=U |
|
553 |
| (Bound i) aconv (Bound j) = i=j |
|
0 | 554 |
| (Abs(_,T,t)) aconv (Abs(_,U,u)) = t aconv u andalso T=U |
2752 | 555 |
| (f$t) aconv (g$u) = (f aconv g) andalso (t aconv u) |
0 | 556 |
| _ aconv _ = false; |
557 |
||
2176 | 558 |
(** Membership, insertion, union for terms **) |
559 |
||
560 |
fun mem_term (_, []) = false |
|
561 |
| mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts); |
|
562 |
||
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
563 |
fun subset_term ([], ys) = true |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
564 |
| subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys); |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
565 |
|
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
566 |
fun eq_set_term (xs, ys) = |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
567 |
xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs)); |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
568 |
|
2176 | 569 |
fun ins_term(t,ts) = if mem_term(t,ts) then ts else t :: ts; |
570 |
||
571 |
fun union_term (xs, []) = xs |
|
572 |
| union_term ([], ys) = ys |
|
573 |
| union_term ((x :: xs), ys) = union_term (xs, ins_term (x, ys)); |
|
574 |
||
5585 | 575 |
fun inter_term ([], ys) = [] |
576 |
| inter_term (x::xs, ys) = |
|
577 |
if mem_term (x,ys) then x :: inter_term(xs,ys) else inter_term(xs,ys); |
|
578 |
||
2176 | 579 |
(** Equality, membership and insertion of sorts (string lists) **) |
580 |
||
581 |
fun eq_sort ([]:sort, []) = true |
|
582 |
| eq_sort ((s::ss), (t::ts)) = s=t andalso eq_sort(ss,ts) |
|
583 |
| eq_sort (_, _) = false; |
|
584 |
||
585 |
fun mem_sort (_:sort, []) = false |
|
586 |
| mem_sort (S, S'::Ss) = eq_sort (S, S') orelse mem_sort(S,Ss); |
|
587 |
||
588 |
fun ins_sort(S,Ss) = if mem_sort(S,Ss) then Ss else S :: Ss; |
|
589 |
||
590 |
fun union_sort (xs, []) = xs |
|
591 |
| union_sort ([], ys) = ys |
|
592 |
| union_sort ((x :: xs), ys) = union_sort (xs, ins_sort (x, ys)); |
|
593 |
||
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
594 |
fun subset_sort ([], ys) = true |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
595 |
| subset_sort (x :: xs, ys) = mem_sort (x, ys) andalso subset_sort(xs, ys); |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
596 |
|
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
597 |
fun eq_set_sort (xs, ys) = |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
598 |
xs = ys orelse (subset_sort (xs, ys) andalso subset_sort (ys, xs)); |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2176
diff
changeset
|
599 |
|
7638 | 600 |
val rems_sort = gen_rems eq_sort; |
601 |
||
0 | 602 |
(*are two term lists alpha-convertible in corresponding elements?*) |
603 |
fun aconvs ([],[]) = true |
|
604 |
| aconvs (t::ts, u::us) = t aconv u andalso aconvs(ts,us) |
|
605 |
| aconvs _ = false; |
|
606 |
||
13000 | 607 |
(*A fast unification filter: true unless the two terms cannot be unified. |
0 | 608 |
Terms must be NORMAL. Treats all Vars as distinct. *) |
609 |
fun could_unify (t,u) = |
|
610 |
let fun matchrands (f$t, g$u) = could_unify(t,u) andalso matchrands(f,g) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
611 |
| matchrands _ = true |
0 | 612 |
in case (head_of t , head_of u) of |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
613 |
(_, Var _) => true |
0 | 614 |
| (Var _, _) => true |
615 |
| (Const(a,_), Const(b,_)) => a=b andalso matchrands(t,u) |
|
616 |
| (Free(a,_), Free(b,_)) => a=b andalso matchrands(t,u) |
|
617 |
| (Bound i, Bound j) => i=j andalso matchrands(t,u) |
|
618 |
| (Abs _, _) => true (*because of possible eta equality*) |
|
619 |
| (_, Abs _) => true |
|
620 |
| _ => false |
|
621 |
end; |
|
622 |
||
623 |
(*Substitute new for free occurrences of old in a term*) |
|
624 |
fun subst_free [] = (fn t=>t) |
|
625 |
| subst_free pairs = |
|
13000 | 626 |
let fun substf u = |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
627 |
case gen_assoc (op aconv) (pairs, u) of |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
628 |
Some u' => u' |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
629 |
| None => (case u of Abs(a,T,t) => Abs(a, T, substf t) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
630 |
| t$u' => substf t $ substf u' |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
631 |
| _ => u) |
0 | 632 |
in substf end; |
633 |
||
634 |
(*a total, irreflexive ordering on index names*) |
|
635 |
fun xless ((a,i), (b,j): indexname) = i<j orelse (i=j andalso a<b); |
|
636 |
||
637 |
||
13000 | 638 |
(*Abstraction of the term "body" over its occurrences of v, |
0 | 639 |
which must contain no loose bound variables. |
640 |
The resulting term is ready to become the body of an Abs.*) |
|
641 |
fun abstract_over (v,body) = |
|
642 |
let fun abst (lev,u) = if (v aconv u) then (Bound lev) else |
|
643 |
(case u of |
|
644 |
Abs(a,T,t) => Abs(a, T, abst(lev+1, t)) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
645 |
| f$rand => abst(lev,f) $ abst(lev,rand) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
646 |
| _ => u) |
0 | 647 |
in abst(0,body) end; |
648 |
||
13665 | 649 |
fun lambda (v as Free (x, T)) t = Abs (x, T, abstract_over (v, t)) |
650 |
| lambda (v as Var ((x, _), T)) t = Abs (x, T, abstract_over (v, t)) |
|
651 |
| lambda v t = raise TERM ("lambda", [v, t]); |
|
0 | 652 |
|
653 |
(*Form an abstraction over a free variable.*) |
|
654 |
fun absfree (a,T,body) = Abs(a, T, abstract_over (Free(a,T), body)); |
|
655 |
||
656 |
(*Abstraction over a list of free variables*) |
|
657 |
fun list_abs_free ([ ] , t) = t |
|
13000 | 658 |
| list_abs_free ((a,T)::vars, t) = |
0 | 659 |
absfree(a, T, list_abs_free(vars,t)); |
660 |
||
661 |
(*Quantification over a list of free variables*) |
|
662 |
fun list_all_free ([], t: term) = t |
|
13000 | 663 |
| list_all_free ((a,T)::vars, t) = |
0 | 664 |
(all T) $ (absfree(a, T, list_all_free(vars,t))); |
665 |
||
666 |
(*Quantification over a list of variables (already bound in body) *) |
|
667 |
fun list_all ([], t) = t |
|
13000 | 668 |
| list_all ((a,T)::vars, t) = |
0 | 669 |
(all T) $ (Abs(a, T, list_all(vars,t))); |
670 |
||
13000 | 671 |
(*Replace the ATOMIC term ti by ui; instl = [(t1,u1), ..., (tn,un)]. |
0 | 672 |
A simultaneous substitution: [ (a,b), (b,a) ] swaps a and b. *) |
673 |
fun subst_atomic [] t = t : term |
|
674 |
| subst_atomic (instl: (term*term) list) t = |
|
675 |
let fun subst (Abs(a,T,body)) = Abs(a, T, subst body) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
676 |
| subst (f$t') = subst f $ subst t' |
9721 | 677 |
| subst t = if_none (assoc(instl,t)) t |
0 | 678 |
in subst t end; |
679 |
||
728
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
lcp
parents:
375
diff
changeset
|
680 |
(*Substitute for type Vars in a type*) |
0 | 681 |
fun typ_subst_TVars iTs T = if null iTs then T else |
682 |
let fun subst(Type(a,Ts)) = Type(a, map subst Ts) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
683 |
| subst(T as TFree _) = T |
9721 | 684 |
| subst(T as TVar(ixn,_)) = if_none (assoc(iTs,ixn)) T |
0 | 685 |
in subst T end; |
686 |
||
728
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
lcp
parents:
375
diff
changeset
|
687 |
(*Substitute for type Vars in a term*) |
0 | 688 |
val subst_TVars = map_term_types o typ_subst_TVars; |
689 |
||
728
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
lcp
parents:
375
diff
changeset
|
690 |
(*Substitute for Vars in a term; see also envir/norm_term*) |
0 | 691 |
fun subst_Vars itms t = if null itms then t else |
9721 | 692 |
let fun subst(v as Var(ixn,_)) = if_none (assoc(itms,ixn)) v |
0 | 693 |
| subst(Abs(a,T,t)) = Abs(a,T,subst t) |
694 |
| subst(f$t) = subst f $ subst t |
|
695 |
| subst(t) = t |
|
696 |
in subst t end; |
|
697 |
||
728
9a973c3ba350
Pure/term: commented typ_subst_TVars, subst_TVars, subst_Vars, subst_vars
lcp
parents:
375
diff
changeset
|
698 |
(*Substitute for type/term Vars in a term; see also envir/norm_term*) |
0 | 699 |
fun subst_vars(iTs,itms) = if null iTs then subst_Vars itms else |
700 |
let fun subst(Const(a,T)) = Const(a,typ_subst_TVars iTs T) |
|
701 |
| subst(Free(a,T)) = Free(a,typ_subst_TVars iTs T) |
|
702 |
| subst(v as Var(ixn,T)) = (case assoc(itms,ixn) of |
|
703 |
None => Var(ixn,typ_subst_TVars iTs T) |
|
704 |
| Some t => t) |
|
705 |
| subst(b as Bound _) = b |
|
706 |
| subst(Abs(a,T,t)) = Abs(a,typ_subst_TVars iTs T,subst t) |
|
707 |
| subst(f$t) = subst f $ subst t |
|
708 |
in subst end; |
|
709 |
||
710 |
||
711 |
(*Computing the maximum index of a typ*) |
|
2146 | 712 |
fun maxidx_of_typ(Type(_,Ts)) = maxidx_of_typs Ts |
0 | 713 |
| maxidx_of_typ(TFree _) = ~1 |
2146 | 714 |
| maxidx_of_typ(TVar((_,i),_)) = i |
715 |
and maxidx_of_typs [] = ~1 |
|
716 |
| maxidx_of_typs (T::Ts) = Int.max(maxidx_of_typ T, maxidx_of_typs Ts); |
|
0 | 717 |
|
718 |
||
719 |
(*Computing the maximum index of a term*) |
|
720 |
fun maxidx_of_term (Const(_,T)) = maxidx_of_typ T |
|
721 |
| maxidx_of_term (Bound _) = ~1 |
|
722 |
| maxidx_of_term (Free(_,T)) = maxidx_of_typ T |
|
2146 | 723 |
| maxidx_of_term (Var ((_,i), T)) = Int.max(i, maxidx_of_typ T) |
724 |
| maxidx_of_term (Abs (_,T,u)) = Int.max(maxidx_of_term u, maxidx_of_typ T) |
|
725 |
| maxidx_of_term (f$t) = Int.max(maxidx_of_term f, maxidx_of_term t); |
|
0 | 726 |
|
13665 | 727 |
fun maxidx_of_terms ts = foldl Int.max (~1, map maxidx_of_term ts); |
728 |
||
0 | 729 |
|
730 |
(* Increment the index of all Poly's in T by k *) |
|
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
731 |
fun incr_tvar k = map_type_tvar (fn ((a,i),S) => TVar((a,i+k),S)); |
0 | 732 |
|
733 |
||
734 |
(**** Syntax-related declarations ****) |
|
735 |
||
736 |
||
4626 | 737 |
(*Dummy type for parsing and printing. Will be replaced during type inference. *) |
0 | 738 |
val dummyT = Type("dummy",[]); |
739 |
||
4694 | 740 |
(*read a numeral of the given radix, normally 10*) |
741 |
fun read_radixint (radix: int, cs) : int * string list = |
|
0 | 742 |
let val zero = ord"0" |
743 |
val limit = zero+radix |
|
744 |
fun scan (num,[]) = (num,[]) |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
745 |
| scan (num, c::cs) = |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
746 |
if zero <= ord c andalso ord c < limit |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
747 |
then scan(radix*num + ord c - zero, cs) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
748 |
else (num, c::cs) |
0 | 749 |
in scan(0,cs) end; |
750 |
||
5986 | 751 |
fun read_int cs = read_radixint (10, cs); |
752 |
||
753 |
fun octal s = #1 (read_radixint (8, explode s)); |
|
754 |
val oct_char = chr o octal; |
|
0 | 755 |
|
756 |
||
757 |
(*** Printing ***) |
|
758 |
||
759 |
(*Makes a variant of the name c distinct from the names in bs. |
|
12306
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
760 |
First attaches the suffix "a" and then increments this; |
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
761 |
preserves a suffix of underscores "_". *) |
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
762 |
fun variant bs name = |
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
763 |
let |
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
764 |
val (c, u) = pairself implode (Library.take_suffix (equal "_") (Symbol.explode name)); |
12902 | 765 |
fun vary2 c = if ((c ^ u) mem_string bs) then vary2 (Symbol.bump_string c) else c; |
12306
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
766 |
fun vary1 c = if ((c ^ u) mem_string bs) then vary2 (c ^ "a") else c; |
749a04f0cfb0
variant: preserve suffix of underscores (for skolem/internal names etc.);
wenzelm
parents:
11922
diff
changeset
|
767 |
in vary1 (if c = "" then "u" else c) ^ u end; |
0 | 768 |
|
769 |
(*Create variants of the list of names, with priority to the first ones*) |
|
770 |
fun variantlist ([], used) = [] |
|
13000 | 771 |
| variantlist(b::bs, used) = |
0 | 772 |
let val b' = variant used b |
773 |
in b' :: variantlist (bs, b'::used) end; |
|
774 |
||
12499 | 775 |
fun invent_names used prfx n = variantlist (Library.replicate n prfx, prfx :: used); |
776 |
fun invent_type_names used = invent_names used "'"; |
|
11353 | 777 |
|
4017
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
778 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
779 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
780 |
(** Consts etc. **) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
781 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
782 |
fun add_typ_classes (Type (_, Ts), cs) = foldr add_typ_classes (Ts, cs) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
783 |
| add_typ_classes (TFree (_, S), cs) = S union cs |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
784 |
| add_typ_classes (TVar (_, S), cs) = S union cs; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
785 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
786 |
fun add_typ_tycons (Type (c, Ts), cs) = foldr add_typ_tycons (Ts, c ins cs) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
787 |
| add_typ_tycons (_, cs) = cs; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
788 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
789 |
val add_term_classes = it_term_types add_typ_classes; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
790 |
val add_term_tycons = it_term_types add_typ_tycons; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
791 |
|
9319 | 792 |
fun add_term_consts (Const (c, _), cs) = c ins_string cs |
4017
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
793 |
| add_term_consts (t $ u, cs) = add_term_consts (t, add_term_consts (u, cs)) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
794 |
| add_term_consts (Abs (_, _, t), cs) = add_term_consts (t, cs) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
795 |
| add_term_consts (_, cs) = cs; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
796 |
|
13646 | 797 |
fun term_consts t = add_term_consts(t,[]); |
798 |
||
4185 | 799 |
fun exists_Const P t = let |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
800 |
fun ex (Const c ) = P c |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
801 |
| ex (t $ u ) = ex t orelse ex u |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
802 |
| ex (Abs (_, _, t)) = ex t |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
803 |
| ex _ = false |
4185 | 804 |
in ex t end; |
4017
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
805 |
|
4631 | 806 |
fun exists_subterm P = |
807 |
let fun ex t = P t orelse |
|
808 |
(case t of |
|
809 |
u $ v => ex u orelse ex v |
|
810 |
| Abs(_, _, u) => ex u |
|
811 |
| _ => false) |
|
812 |
in ex end; |
|
813 |
||
4017
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
814 |
(*map classes, tycons*) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
815 |
fun map_typ f g (Type (c, Ts)) = Type (g c, map (map_typ f g) Ts) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
816 |
| map_typ f _ (TFree (x, S)) = TFree (x, map f S) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
817 |
| map_typ f _ (TVar (xi, S)) = TVar (xi, map f S); |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
818 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
819 |
(*map classes, tycons, consts*) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
820 |
fun map_term f g h (Const (c, T)) = Const (h c, map_typ f g T) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
821 |
| map_term f g _ (Free (x, T)) = Free (x, map_typ f g T) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
822 |
| map_term f g _ (Var (xi, T)) = Var (xi, map_typ f g T) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
823 |
| map_term _ _ _ (t as Bound _) = t |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
824 |
| map_term f g h (Abs (x, T, t)) = Abs (x, map_typ f g T, map_term f g h t) |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
825 |
| map_term f g h (t $ u) = map_term f g h t $ map_term f g h u; |
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
826 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
827 |
|
63878e2587a7
add_typ_classes, add_typ_tycons, add_term_classes, add_term_tycons,
wenzelm
parents:
3965
diff
changeset
|
828 |
|
0 | 829 |
(** TFrees and TVars **) |
830 |
||
831 |
(*maps (bs,v) to v'::bs this reverses the identifiers bs*) |
|
832 |
fun add_new_id (bs, c) : string list = variant bs c :: bs; |
|
833 |
||
12802
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
834 |
(*Accumulates the names of Frees in the term, suppressing duplicates.*) |
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
835 |
fun add_term_free_names (Free(a,_), bs) = a ins_string bs |
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
836 |
| add_term_free_names (f$u, bs) = add_term_free_names (f, add_term_free_names(u, bs)) |
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
837 |
| add_term_free_names (Abs(_,_,t), bs) = add_term_free_names(t,bs) |
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
838 |
| add_term_free_names (_, bs) = bs; |
c69bd9754473
added add_term_free_names (more precise/efficient than add_term_names);
wenzelm
parents:
12499
diff
changeset
|
839 |
|
0 | 840 |
(*Accumulates the names in the term, suppressing duplicates. |
841 |
Includes Frees and Consts. For choosing unambiguous bound var names.*) |
|
10666 | 842 |
fun add_term_names (Const(a,_), bs) = NameSpace.base a ins_string bs |
2176 | 843 |
| add_term_names (Free(a,_), bs) = a ins_string bs |
0 | 844 |
| add_term_names (f$u, bs) = add_term_names (f, add_term_names(u, bs)) |
845 |
| add_term_names (Abs(_,_,t), bs) = add_term_names(t,bs) |
|
846 |
| add_term_names (_, bs) = bs; |
|
847 |
||
848 |
(*Accumulates the TVars in a type, suppressing duplicates. *) |
|
849 |
fun add_typ_tvars(Type(_,Ts),vs) = foldr add_typ_tvars (Ts,vs) |
|
850 |
| add_typ_tvars(TFree(_),vs) = vs |
|
851 |
| add_typ_tvars(TVar(v),vs) = v ins vs; |
|
852 |
||
853 |
(*Accumulates the TFrees in a type, suppressing duplicates. *) |
|
854 |
fun add_typ_tfree_names(Type(_,Ts),fs) = foldr add_typ_tfree_names (Ts,fs) |
|
2176 | 855 |
| add_typ_tfree_names(TFree(f,_),fs) = f ins_string fs |
0 | 856 |
| add_typ_tfree_names(TVar(_),fs) = fs; |
857 |
||
858 |
fun add_typ_tfrees(Type(_,Ts),fs) = foldr add_typ_tfrees (Ts,fs) |
|
859 |
| add_typ_tfrees(TFree(f),fs) = f ins fs |
|
860 |
| add_typ_tfrees(TVar(_),fs) = fs; |
|
861 |
||
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
862 |
fun add_typ_varnames(Type(_,Ts),nms) = foldr add_typ_varnames (Ts,nms) |
2176 | 863 |
| add_typ_varnames(TFree(nm,_),nms) = nm ins_string nms |
864 |
| add_typ_varnames(TVar((nm,_),_),nms) = nm ins_string nms; |
|
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
865 |
|
0 | 866 |
(*Accumulates the TVars in a term, suppressing duplicates. *) |
867 |
val add_term_tvars = it_term_types add_typ_tvars; |
|
868 |
||
869 |
(*Accumulates the TFrees in a term, suppressing duplicates. *) |
|
870 |
val add_term_tfrees = it_term_types add_typ_tfrees; |
|
871 |
val add_term_tfree_names = it_term_types add_typ_tfree_names; |
|
872 |
||
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
873 |
val add_term_tvarnames = it_term_types add_typ_varnames; |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
874 |
|
0 | 875 |
(*Non-list versions*) |
876 |
fun typ_tfrees T = add_typ_tfrees(T,[]); |
|
877 |
fun typ_tvars T = add_typ_tvars(T,[]); |
|
878 |
fun term_tfrees t = add_term_tfrees(t,[]); |
|
879 |
fun term_tvars t = add_term_tvars(t,[]); |
|
880 |
||
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
881 |
(*special code to enforce left-to-right collection of TVar-indexnames*) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
882 |
|
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
883 |
fun add_typ_ixns(ixns,Type(_,Ts)) = foldl add_typ_ixns (ixns,Ts) |
13000 | 884 |
| add_typ_ixns(ixns,TVar(ixn,_)) = if mem_ix (ixn, ixns) then ixns |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
885 |
else ixns@[ixn] |
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
886 |
| add_typ_ixns(ixns,TFree(_)) = ixns; |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
887 |
|
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
888 |
fun add_term_tvar_ixns(Const(_,T),ixns) = add_typ_ixns(ixns,T) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
889 |
| add_term_tvar_ixns(Free(_,T),ixns) = add_typ_ixns(ixns,T) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
890 |
| add_term_tvar_ixns(Var(_,T),ixns) = add_typ_ixns(ixns,T) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
891 |
| add_term_tvar_ixns(Bound _,ixns) = ixns |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
892 |
| add_term_tvar_ixns(Abs(_,T,t),ixns) = |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
893 |
add_term_tvar_ixns(t,add_typ_ixns(ixns,T)) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
894 |
| add_term_tvar_ixns(f$t,ixns) = |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
895 |
add_term_tvar_ixns(t,add_term_tvar_ixns(f,ixns)); |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
728
diff
changeset
|
896 |
|
0 | 897 |
(** Frees and Vars **) |
898 |
||
899 |
(*a partial ordering (not reflexive) for atomic terms*) |
|
900 |
fun atless (Const (a,_), Const (b,_)) = a<b |
|
901 |
| atless (Free (a,_), Free (b,_)) = a<b |
|
902 |
| atless (Var(v,_), Var(w,_)) = xless(v,w) |
|
903 |
| atless (Bound i, Bound j) = i<j |
|
904 |
| atless _ = false; |
|
905 |
||
906 |
(*insert atomic term into partially sorted list, suppressing duplicates (?)*) |
|
907 |
fun insert_aterm (t,us) = |
|
908 |
let fun inserta [] = [t] |
|
13000 | 909 |
| inserta (us as u::us') = |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
910 |
if atless(t,u) then t::us |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
911 |
else if t=u then us (*duplicate*) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
912 |
else u :: inserta(us') |
0 | 913 |
in inserta us end; |
914 |
||
915 |
(*Accumulates the Vars in the term, suppressing duplicates*) |
|
916 |
fun add_term_vars (t, vars: term list) = case t of |
|
917 |
Var _ => insert_aterm(t,vars) |
|
918 |
| Abs (_,_,body) => add_term_vars(body,vars) |
|
919 |
| f$t => add_term_vars (f, add_term_vars(t, vars)) |
|
920 |
| _ => vars; |
|
921 |
||
922 |
fun term_vars t = add_term_vars(t,[]); |
|
923 |
||
924 |
(*Accumulates the Frees in the term, suppressing duplicates*) |
|
925 |
fun add_term_frees (t, frees: term list) = case t of |
|
926 |
Free _ => insert_aterm(t,frees) |
|
927 |
| Abs (_,_,body) => add_term_frees(body,frees) |
|
928 |
| f$t => add_term_frees (f, add_term_frees(t, frees)) |
|
929 |
| _ => frees; |
|
930 |
||
931 |
fun term_frees t = add_term_frees(t,[]); |
|
932 |
||
933 |
(*Given an abstraction over P, replaces the bound variable by a Free variable |
|
934 |
having a unique name. *) |
|
935 |
fun variant_abs (a,T,P) = |
|
936 |
let val b = variant (add_term_names(P,[])) a |
|
2192
3bf092b5310b
Optimizations: removal of polymorphic equality; one-argument case
paulson
parents:
2182
diff
changeset
|
937 |
in (b, subst_bound (Free(b,T), P)) end; |
0 | 938 |
|
939 |
(* renames and reverses the strings in vars away from names *) |
|
940 |
fun rename_aTs names vars : (string*typ)list = |
|
941 |
let fun rename_aT (vars,(a,T)) = |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
942 |
(variant (map #1 vars @ names) a, T) :: vars |
0 | 943 |
in foldl rename_aT ([],vars) end; |
944 |
||
945 |
fun rename_wrt_term t = rename_aTs (add_term_names(t,[])); |
|
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
946 |
|
1417 | 947 |
|
4286
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
948 |
(* left-ro-right traversal *) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
949 |
|
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
950 |
(*foldl atoms of type*) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
951 |
fun foldl_atyps f (x, Type (_, Ts)) = foldl (foldl_atyps f) (x, Ts) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
952 |
| foldl_atyps f x_atom = f x_atom; |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
953 |
|
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
954 |
(*foldl atoms of term*) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
955 |
fun foldl_aterms f (x, t $ u) = foldl_aterms f (foldl_aterms f (x, t), u) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
956 |
| foldl_aterms f (x, Abs (_, _, t)) = foldl_aterms f (x, t) |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
957 |
| foldl_aterms f x_atom = f x_atom; |
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
958 |
|
6548
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
959 |
fun foldl_map_aterms f (x, t $ u) = |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
960 |
let val (x', t') = foldl_map_aterms f (x, t); val (x'', u') = foldl_map_aterms f (x', u); |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
961 |
in (x'', t' $ u') end |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
962 |
| foldl_map_aterms f (x, Abs (a, T, t)) = |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
963 |
let val (x', t') = foldl_map_aterms f (x, t) in (x', Abs (a, T, t')) end |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
964 |
| foldl_map_aterms f x_atom = f x_atom; |
9b108dd75c25
val foldl_map_aterms: ('a * term -> 'a * term) -> 'a * term -> 'a * term;
wenzelm
parents:
6033
diff
changeset
|
965 |
|
4286
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
966 |
(*foldl types of term*) |
8609 | 967 |
fun foldl_term_types f (x, t as Const (_, T)) = f t (x, T) |
968 |
| foldl_term_types f (x, t as Free (_, T)) = f t (x, T) |
|
969 |
| foldl_term_types f (x, t as Var (_, T)) = f t (x, T) |
|
970 |
| foldl_term_types f (x, Bound _) = x |
|
971 |
| foldl_term_types f (x, t as Abs (_, T, b)) = foldl_term_types f (f t (x, T), b) |
|
972 |
| foldl_term_types f (x, t $ u) = foldl_term_types f (foldl_term_types f (x, t), u); |
|
973 |
||
974 |
fun foldl_types f = foldl_term_types (fn _ => f); |
|
4286
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
975 |
|
12499 | 976 |
(*collect variables*) |
977 |
val add_tvarsT = foldl_atyps (fn (vs, TVar v) => v ins vs | (vs, _) => vs); |
|
978 |
val add_tvars = foldl_types add_tvarsT; |
|
979 |
val add_vars = foldl_aterms (fn (vs, Var v) => v ins vs | (vs, _) => vs); |
|
980 |
val add_frees = foldl_aterms (fn (vs, Free v) => v ins vs | (vs, _) => vs); |
|
981 |
||
4286
a09e3e6da2de
added foldl_atyps: ('a * typ -> 'a) -> 'a * typ -> 'a;
wenzelm
parents:
4188
diff
changeset
|
982 |
|
1417 | 983 |
|
4444 | 984 |
(** type and term orders **) |
985 |
||
986 |
fun indexname_ord ((x, i), (y, j)) = |
|
987 |
(case int_ord (i, j) of EQUAL => string_ord (x, y) | ord => ord); |
|
988 |
||
13000 | 989 |
val sort_ord = list_ord string_ord; |
990 |
||
4444 | 991 |
|
992 |
(* typ_ord *) |
|
993 |
||
13000 | 994 |
fun typ_ord (Type x, Type y) = prod_ord string_ord typs_ord (x, y) |
4444 | 995 |
| typ_ord (Type _, _) = GREATER |
996 |
| typ_ord (TFree _, Type _) = LESS |
|
13000 | 997 |
| typ_ord (TFree x, TFree y) = prod_ord string_ord sort_ord (x, y) |
4444 | 998 |
| typ_ord (TFree _, TVar _) = GREATER |
999 |
| typ_ord (TVar _, Type _) = LESS |
|
1000 |
| typ_ord (TVar _, TFree _) = LESS |
|
13000 | 1001 |
| typ_ord (TVar x, TVar y) = prod_ord indexname_ord sort_ord (x, y) |
4444 | 1002 |
and typs_ord Ts_Us = list_ord typ_ord Ts_Us; |
1003 |
||
1004 |
||
1005 |
(* term_ord *) |
|
1006 |
||
1007 |
(*a linear well-founded AC-compatible ordering for terms: |
|
1008 |
s < t <=> 1. size(s) < size(t) or |
|
1009 |
2. size(s) = size(t) and s=f(...) and t=g(...) and f<g or |
|
1010 |
3. size(s) = size(t) and s=f(s1..sn) and t=f(t1..tn) and |
|
1011 |
(s1..sn) < (t1..tn) (lexicographically)*) |
|
1012 |
||
1013 |
fun dest_hd (Const (a, T)) = (((a, 0), T), 0) |
|
1014 |
| dest_hd (Free (a, T)) = (((a, 0), T), 1) |
|
1015 |
| dest_hd (Var v) = (v, 2) |
|
1016 |
| dest_hd (Bound i) = ((("", i), dummyT), 3) |
|
1017 |
| dest_hd (Abs (_, T, _)) = ((("", 0), T), 4); |
|
1018 |
||
1019 |
fun term_ord (Abs (_, T, t), Abs(_, U, u)) = |
|
1020 |
(case term_ord (t, u) of EQUAL => typ_ord (T, U) | ord => ord) |
|
1021 |
| term_ord (t, u) = |
|
1022 |
(case int_ord (size_of_term t, size_of_term u) of |
|
1023 |
EQUAL => |
|
1024 |
let val (f, ts) = strip_comb t and (g, us) = strip_comb u in |
|
1025 |
(case hd_ord (f, g) of EQUAL => terms_ord (ts, us) | ord => ord) |
|
1026 |
end |
|
1027 |
| ord => ord) |
|
1028 |
and hd_ord (f, g) = |
|
1029 |
prod_ord (prod_ord indexname_ord typ_ord) int_ord (dest_hd f, dest_hd g) |
|
1030 |
and terms_ord (ts, us) = list_ord term_ord (ts, us); |
|
1031 |
||
1032 |
fun termless tu = (term_ord tu = LESS); |
|
1033 |
||
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1034 |
structure Vartab = TableFun(type key = indexname val ord = indexname_ord); |
13000 | 1035 |
structure Typtab = TableFun(type key = typ val ord = typ_ord); |
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1036 |
structure Termtab = TableFun(type key = term val ord = term_ord); |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1037 |
|
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1038 |
(*Substitute for type Vars in a type, version using Vartab*) |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1039 |
fun typ_subst_TVars_Vartab iTs T = if Vartab.is_empty iTs then T else |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1040 |
let fun subst(Type(a, Ts)) = Type(a, map subst Ts) |
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1041 |
| subst(T as TFree _) = T |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1042 |
| subst(T as TVar(ixn, _)) = |
8408
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1043 |
(case Vartab.lookup (iTs, ixn) of None => T | Some(U) => U) |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1044 |
in subst T end; |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1045 |
|
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1046 |
(*Substitute for type Vars in a term, version using Vartab*) |
4d981311dab7
Added functions subst_TVars_Vartab and typ_subst_TVars_Vartab.
berghofe
parents:
7638
diff
changeset
|
1047 |
val subst_TVars_Vartab = map_term_types o typ_subst_TVars_Vartab; |
4444 | 1048 |
|
1049 |
||
13000 | 1050 |
(*** Compression of terms and types by sharing common subtrees. |
1051 |
Saves 50-75% on storage requirements. As it is a bit slow, |
|
1052 |
it should be called only for axioms, stored theorems, etc. |
|
1053 |
Recorded term and type fragments are never disposed. ***) |
|
1417 | 1054 |
|
1055 |
(** Sharing of types **) |
|
1056 |
||
13000 | 1057 |
val memo_types = ref (Typtab.empty: typ Typtab.table); |
1417 | 1058 |
|
1059 |
fun compress_type T = |
|
13000 | 1060 |
(case Typtab.lookup (! memo_types, T) of |
1061 |
Some T' => T' |
|
1062 |
| None => |
|
1063 |
let val T' = (case T of Type (a, Ts) => Type (a, map compress_type Ts) | _ => T) |
|
1064 |
in memo_types := Typtab.update ((T', T'), ! memo_types); T' end); |
|
1065 |
||
1417 | 1066 |
|
1067 |
(** Sharing of atomic terms **) |
|
1068 |
||
13000 | 1069 |
val memo_terms = ref (Termtab.empty : term Termtab.table); |
1417 | 1070 |
|
1071 |
fun share_term (t $ u) = share_term t $ share_term u |
|
13000 | 1072 |
| share_term (Abs (a, T, u)) = Abs (a, T, share_term u) |
1417 | 1073 |
| share_term t = |
13000 | 1074 |
(case Termtab.lookup (! memo_terms, t) of |
1075 |
Some t' => t' |
|
1076 |
| None => (memo_terms := Termtab.update ((t, t), ! memo_terms); t)); |
|
1417 | 1077 |
|
1078 |
val compress_term = share_term o map_term_types compress_type; |
|
1079 |
||
4444 | 1080 |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1081 |
(* dummy patterns *) |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1082 |
|
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1083 |
val dummy_patternN = "dummy_pattern"; |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1084 |
|
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1085 |
fun is_dummy_pattern (Const ("dummy_pattern", _)) = true |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1086 |
| is_dummy_pattern _ = false; |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1087 |
|
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1088 |
fun no_dummy_patterns tm = |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1089 |
if not (foldl_aterms (fn (b, t) => b orelse is_dummy_pattern t) (false, tm)) then tm |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1090 |
else raise TERM ("Illegal occurrence of '_' dummy pattern", [tm]); |
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1091 |
|
11903 | 1092 |
fun replace_dummy Ts (i, Const ("dummy_pattern", T)) = |
1093 |
(i + 1, list_comb (Var (("_dummy_", i), Ts ---> T), map Bound (0 upto length Ts - 1))) |
|
1094 |
| replace_dummy Ts (i, Abs (x, T, t)) = |
|
1095 |
let val (i', t') = replace_dummy (T :: Ts) (i, t) |
|
1096 |
in (i', Abs (x, T, t')) end |
|
1097 |
| replace_dummy Ts (i, t $ u) = |
|
1098 |
let val (i', t') = replace_dummy Ts (i, t); val (i'', u') = replace_dummy Ts (i', u) |
|
1099 |
in (i'', t' $ u') end |
|
1100 |
| replace_dummy _ (i, a) = (i, a); |
|
1101 |
||
1102 |
val replace_dummy_patterns = replace_dummy []; |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1103 |
|
10552 | 1104 |
fun is_replaced_dummy_pattern ("_dummy_", _) = true |
1105 |
| is_replaced_dummy_pattern _ = false; |
|
9536
b79b002f32ae
added dummy_patternN, no_dummy_patterns, replace_dummy_patterns;
wenzelm
parents:
9319
diff
changeset
|
1106 |
|
13484 | 1107 |
|
1108 |
(* adhoc freezing *) |
|
1109 |
||
1110 |
fun adhoc_freeze_vars tm = |
|
1111 |
let |
|
1112 |
fun mk_inst (var as Var ((a, i), T)) = |
|
1113 |
let val x = a ^ Library.gensym "_" ^ string_of_int i |
|
1114 |
in ((var, Free(x, T)), x) end; |
|
1115 |
val (insts, xs) = split_list (map mk_inst (term_vars tm)); |
|
1116 |
in (subst_atomic insts tm, xs) end; |
|
1117 |
||
1118 |
||
1364
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
1119 |
end; |
8ea1a962ad72
files now define a structure to allow SML/NJ to optimize the code
clasohm
parents:
1029
diff
changeset
|
1120 |
|
4444 | 1121 |
|
1122 |
structure BasicTerm: BASIC_TERM = Term; |
|
1123 |
open BasicTerm; |