author | wenzelm |
Tue, 06 May 1997 15:27:35 +0200 | |
changeset 3118 | 24dae6222579 |
parent 2991 | d9f6299dbf9f |
child 3175 | 02d32516bc92 |
permissions | -rw-r--r-- |
256 | 1 |
(* Title: Pure/type.ML |
0 | 2 |
ID: $Id$ |
416 | 3 |
Author: Tobias Nipkow & Lawrence C Paulson |
0 | 4 |
|
2964 | 5 |
Type signatures, unification of types, interface to type inference. |
0 | 6 |
*) |
7 |
||
8 |
signature TYPE = |
|
2964 | 9 |
sig |
10 |
(*TFrees vs TVars*) |
|
621 | 11 |
val no_tvars: typ -> typ |
12 |
val varifyT: typ -> typ |
|
13 |
val unvarifyT: typ -> typ |
|
14 |
val varify: term * string list -> term |
|
2964 | 15 |
val freeze_vars: typ -> typ |
16 |
val thaw_vars: typ -> typ |
|
17 |
val freeze: term -> term |
|
18 |
||
19 |
(*type signatures*) |
|
0 | 20 |
type type_sig |
200 | 21 |
val rep_tsig: type_sig -> |
256 | 22 |
{classes: class list, |
2964 | 23 |
classrel: (class * class list) list, |
256 | 24 |
default: sort, |
963 | 25 |
tycons: (string * int) list, |
621 | 26 |
abbrs: (string * (string list * typ)) list, |
963 | 27 |
arities: (string * (class * sort list) list) list} |
0 | 28 |
val defaultS: type_sig -> sort |
2964 | 29 |
val logical_types: type_sig -> string list |
30 |
||
31 |
val subsort: type_sig -> sort * sort -> bool |
|
32 |
val eq_sort: type_sig -> sort * sort -> bool |
|
33 |
val norm_sort: type_sig -> sort -> sort |
|
34 |
val nonempty_sort: type_sig -> sort list -> sort -> bool |
|
35 |
val rem_sorts: typ -> typ |
|
36 |
||
416 | 37 |
val tsig0: type_sig |
621 | 38 |
val ext_tsig_classes: type_sig -> (class * class list) list -> type_sig |
2964 | 39 |
val ext_tsig_classrel: type_sig -> (class * class) list -> type_sig |
422 | 40 |
val ext_tsig_defsort: type_sig -> sort -> type_sig |
582 | 41 |
val ext_tsig_types: type_sig -> (string * int) list -> type_sig |
621 | 42 |
val ext_tsig_abbrs: type_sig -> (string * string list * typ) list -> type_sig |
963 | 43 |
val ext_tsig_arities: type_sig -> (string * sort list * sort)list -> type_sig |
256 | 44 |
val merge_tsigs: type_sig * type_sig -> type_sig |
2964 | 45 |
|
46 |
val typ_errors: type_sig -> typ * string list -> string list |
|
256 | 47 |
val cert_typ: type_sig -> typ -> typ |
48 |
val norm_typ: type_sig -> typ -> typ |
|
2964 | 49 |
|
256 | 50 |
val inst_term_tvars: type_sig * (indexname * typ) list -> term -> term |
2964 | 51 |
|
52 |
(*type matching*) |
|
53 |
exception TYPE_MATCH |
|
256 | 54 |
val typ_match: type_sig -> (indexname * typ) list * (typ * typ) |
55 |
-> (indexname * typ) list |
|
2964 | 56 |
val typ_instance: type_sig * typ * typ -> bool |
57 |
||
58 |
(*type unification*) |
|
59 |
exception TUNIFY |
|
1435
aefcd255ed4a
Removed bug in type unification. Negative indexes are not used any longer.
nipkow
parents:
1392
diff
changeset
|
60 |
val unify: type_sig -> int -> (indexname * typ) list -> (typ * typ) |
aefcd255ed4a
Removed bug in type unification. Negative indexes are not used any longer.
nipkow
parents:
1392
diff
changeset
|
61 |
-> (indexname * typ) list * int |
450 | 62 |
val raw_unify: typ * typ -> bool |
0 | 63 |
|
2964 | 64 |
(*type inference*) |
65 |
val get_sort: type_sig -> (indexname -> sort option) -> (indexname * sort) list |
|
66 |
-> indexname -> sort |
|
67 |
val constrain: term -> typ -> term |
|
2979 | 68 |
val infer_types: (term -> Pretty.T) -> (typ -> Pretty.T) |
69 |
-> type_sig -> (string -> typ option) -> (indexname -> typ option) |
|
70 |
-> (indexname -> sort option) -> string list -> bool -> typ list -> term list |
|
2964 | 71 |
-> term list * (indexname * typ) list |
72 |
end; |
|
73 |
||
74 |
structure Type: TYPE = |
|
0 | 75 |
struct |
76 |
||
2964 | 77 |
|
621 | 78 |
(*** TFrees vs TVars ***) |
79 |
||
80 |
(*disallow TVars*) |
|
81 |
fun no_tvars T = |
|
82 |
if null (typ_tvars T) then T |
|
83 |
else raise_type "Illegal schematic type variable(s)" [T] []; |
|
84 |
||
2964 | 85 |
(* varify, unvarify *) |
621 | 86 |
|
2964 | 87 |
val varifyT = map_type_tfree (fn (a, S) => TVar ((a, 0), S)); |
88 |
||
621 | 89 |
fun unvarifyT (Type (a, Ts)) = Type (a, map unvarifyT Ts) |
90 |
| unvarifyT (TVar ((a, 0), S)) = TFree (a, S) |
|
91 |
| unvarifyT T = T; |
|
92 |
||
93 |
fun varify (t, fixed) = |
|
94 |
let |
|
95 |
val fs = add_term_tfree_names (t, []) \\ fixed; |
|
96 |
val ixns = add_term_tvar_ixns (t, []); |
|
97 |
val fmap = fs ~~ variantlist (fs, map #1 ixns) |
|
2964 | 98 |
fun thaw (f as (a, S)) = |
99 |
(case assoc (fmap, a) of |
|
100 |
None => TFree f |
|
101 |
| Some b => TVar ((b, 0), S)); |
|
102 |
in |
|
103 |
map_term_types (map_type_tfree thaw) t |
|
104 |
end; |
|
105 |
||
106 |
||
107 |
(* thaw, freeze *) |
|
621 | 108 |
|
2964 | 109 |
val thaw_vars = |
110 |
let |
|
111 |
fun thaw (f as (a, S)) = |
|
112 |
(case explode a of |
|
113 |
"?" :: "'" :: vn => |
|
114 |
let val ((b, i), _) = Syntax.scan_varname vn in |
|
115 |
TVar (("'" ^ b, i), S) |
|
116 |
end |
|
117 |
| _ => TFree f) |
|
118 |
in map_type_tfree thaw end; |
|
119 |
||
120 |
val freeze_vars = |
|
121 |
map_type_tvar (fn (v, S) => TFree (Syntax.string_of_vname v, S)); |
|
621 | 122 |
|
123 |
||
2964 | 124 |
local |
125 |
fun nextname (pref, c) = |
|
126 |
if c = "z" then (pref ^ "a", "a") |
|
127 |
else (pref, chr (ord c + 1)); |
|
416 | 128 |
|
2964 | 129 |
fun newtvars used = |
130 |
let |
|
131 |
fun new ([], _, vmap) = vmap |
|
132 |
| new (ixn :: ixns, p as (pref, c), vmap) = |
|
133 |
let val nm = pref ^ c in |
|
134 |
if nm mem_string used then new (ixn :: ixns, nextname p, vmap) |
|
135 |
else new (ixns, nextname p, (ixn, nm) :: vmap) |
|
136 |
end |
|
137 |
in new end; |
|
416 | 138 |
|
2964 | 139 |
(*Turn all TVars which satisfy p into new (if freeze then TFrees else TVars). |
140 |
Note that if t contains frozen TVars there is the possibility that a TVar is |
|
141 |
turned into one of those. This is sound but not complete.*) |
|
416 | 142 |
|
2964 | 143 |
fun convert used freeze p t = |
144 |
let |
|
145 |
val used = |
|
146 |
if freeze then add_term_tfree_names (t, used) |
|
147 |
else used union (map #1 (filter_out p (add_term_tvar_ixns (t, [])))); |
|
148 |
val ixns = filter p (add_term_tvar_ixns (t, [])); |
|
149 |
val vmap = newtvars used (ixns, ("'", "a"), []); |
|
150 |
fun conv (var as (ixn, S)) = |
|
151 |
(case assoc (vmap, ixn) of |
|
152 |
None => TVar(var) |
|
153 |
| Some a => if freeze then TFree (a, S) else TVar ((a, 0), S)); |
|
154 |
in |
|
155 |
map_term_types (map_type_tvar conv) t |
|
156 |
end; |
|
157 |
in |
|
158 |
fun freeze t = convert (add_term_tfree_names(t,[])) true (K true) t; |
|
159 |
end; |
|
256 | 160 |
|
161 |
||
162 |
||
416 | 163 |
(*** type signatures ***) |
256 | 164 |
|
2964 | 165 |
(* type type_sig *) |
166 |
||
256 | 167 |
(* |
168 |
classes: |
|
2964 | 169 |
list of all declared classes; |
0 | 170 |
|
2964 | 171 |
classrel: |
172 |
(see Pure/sorts.ML) |
|
256 | 173 |
|
174 |
default: |
|
2964 | 175 |
default sort attached to all unconstrained type vars; |
256 | 176 |
|
963 | 177 |
tycons: |
2964 | 178 |
association list of all declared types with the number of their |
256 | 179 |
arguments; |
180 |
||
181 |
abbrs: |
|
2964 | 182 |
association list of type abbreviations; |
256 | 183 |
|
963 | 184 |
arities: |
2964 | 185 |
(see Pure/sorts.ML) |
0 | 186 |
*) |
187 |
||
256 | 188 |
datatype type_sig = |
189 |
TySg of { |
|
190 |
classes: class list, |
|
2964 | 191 |
classrel: (class * class list) list, |
256 | 192 |
default: sort, |
963 | 193 |
tycons: (string * int) list, |
621 | 194 |
abbrs: (string * (string list * typ)) list, |
2964 | 195 |
arities: (string * (class * sort list) list) list}; |
256 | 196 |
|
189 | 197 |
fun rep_tsig (TySg comps) = comps; |
0 | 198 |
|
256 | 199 |
fun defaultS (TySg {default, ...}) = default; |
200 |
||
2964 | 201 |
fun logical_types (TySg {classrel, arities, tycons, ...}) = |
202 |
let |
|
203 |
fun log_class c = Sorts.class_le classrel (c, logicC); |
|
204 |
fun log_type t = exists (log_class o #1) (assocs arities t); |
|
205 |
in |
|
206 |
filter log_type (map #1 tycons) |
|
207 |
end; |
|
208 |
||
209 |
||
210 |
(* sorts *) |
|
211 |
||
212 |
(* FIXME declared!? *) |
|
213 |
||
214 |
fun subsort (TySg {classrel, ...}) = Sorts.sort_le classrel; |
|
215 |
fun eq_sort (TySg {classrel, ...}) = Sorts.sort_eq classrel; |
|
216 |
fun norm_sort (TySg {classrel, ...}) = Sorts.norm_sort classrel; |
|
217 |
||
218 |
fun nonempty_sort (tsig as TySg {classrel, arities, ...}) hyps S = |
|
219 |
Sorts.nonempty_sort classrel arities hyps S; |
|
220 |
||
221 |
fun rem_sorts (Type (a, tys)) = Type (a, map rem_sorts tys) |
|
222 |
| rem_sorts (TFree (x, _)) = TFree (x, []) |
|
223 |
| rem_sorts (TVar (xi, _)) = TVar (xi, []); |
|
224 |
||
256 | 225 |
|
582 | 226 |
(* error messages *) |
256 | 227 |
|
416 | 228 |
fun undcl_class c = "Undeclared class " ^ quote c; |
2233
f919bdd5f9b6
Removed or eta-expanded some declarations that are illegal under value
paulson
parents:
2182
diff
changeset
|
229 |
fun err_undcl_class s = error (undcl_class s); |
0 | 230 |
|
422 | 231 |
fun err_dup_classes cs = |
232 |
error ("Duplicate declaration of class(es) " ^ commas_quote cs); |
|
416 | 233 |
|
234 |
fun undcl_type c = "Undeclared type constructor " ^ quote c; |
|
256 | 235 |
|
582 | 236 |
fun err_neg_args c = |
237 |
error ("Negative number of arguments of type constructor " ^ quote c); |
|
238 |
||
416 | 239 |
fun err_dup_tycon c = |
240 |
error ("Duplicate declaration of type constructor " ^ quote c); |
|
241 |
||
621 | 242 |
fun dup_tyabbrs ts = |
243 |
"Duplicate declaration of type abbreviation(s) " ^ commas_quote ts; |
|
416 | 244 |
|
245 |
fun ty_confl c = "Conflicting type constructor and abbreviation " ^ quote c; |
|
0 | 246 |
|
247 |
||
2964 | 248 |
(* FIXME err_undcl_class! *) |
0 | 249 |
(* 'leq' checks the partial order on classes according to the |
2964 | 250 |
statements in the association list 'a' (i.e. 'classrel') |
0 | 251 |
*) |
252 |
||
256 | 253 |
fun less a (C, D) = case assoc (a, C) of |
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
254 |
Some ss => D mem_string ss |
621 | 255 |
| None => err_undcl_class C; |
0 | 256 |
|
256 | 257 |
fun leq a (C, D) = C = D orelse less a (C, D); |
0 | 258 |
|
259 |
||
260 |
||
2964 | 261 |
(* FIXME *) |
200 | 262 |
(*Instantiation of type variables in types*) |
263 |
(*Pre: instantiations obey restrictions! *) |
|
264 |
fun inst_typ tye = |
|
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
265 |
let fun inst(var as (v, _)) = case assoc(tye, v) of |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
266 |
Some U => inst_typ tye U |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
267 |
| None => TVar(var) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
268 |
in map_type_tvar inst end; |
0 | 269 |
|
270 |
||
2964 | 271 |
fun check_has_sort (TySg {classrel, arities, ...}, T, S) = |
2991 | 272 |
if Sorts.of_sort classrel arities (T, S) then () |
273 |
else raise_type ("Type not of sort " ^ Sorts.str_of_sort S) [T] []; |
|
0 | 274 |
|
275 |
||
276 |
(*Instantiation of type variables in types *) |
|
256 | 277 |
fun inst_typ_tvars(tsig, tye) = |
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
278 |
let fun inst(var as (v, S)) = case assoc(tye, v) of |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
279 |
Some U => (check_has_sort(tsig, U, S); U) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
280 |
| None => TVar(var) |
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
281 |
in map_type_tvar inst end; |
0 | 282 |
|
283 |
(*Instantiation of type variables in terms *) |
|
2617 | 284 |
fun inst_term_tvars (_,[]) t = t |
285 |
| inst_term_tvars arg t = map_term_types (inst_typ_tvars arg) t; |
|
200 | 286 |
|
287 |
||
1484 | 288 |
(* norm_typ *) |
200 | 289 |
|
2991 | 290 |
(*expand abbreviations and normalize sorts*) |
291 |
fun norm_typ (tsig as TySg {abbrs, ...}) ty = |
|
256 | 292 |
let |
621 | 293 |
val idx = maxidx_of_typ ty + 1; |
294 |
||
2991 | 295 |
fun norm (Type (a, Ts)) = |
256 | 296 |
(case assoc (abbrs, a) of |
2991 | 297 |
Some (vs, U) => norm (inst_typ (map (rpair idx) vs ~~ Ts) (incr_tvar idx U)) |
298 |
| None => Type (a, map norm Ts)) |
|
299 |
| norm (TFree (x, S)) = TFree (x, norm_sort tsig S) |
|
300 |
| norm (TVar (xi, S)) = TVar (xi, norm_sort tsig S); |
|
256 | 301 |
in |
2991 | 302 |
norm ty |
256 | 303 |
end; |
304 |
||
305 |
||
306 |
||
307 |
||
308 |
||
309 |
(** build type signatures **) |
|
310 |
||
2964 | 311 |
fun make_tsig (classes, classrel, default, tycons, abbrs, arities) = |
312 |
TySg {classes = classes, classrel = classrel, default = default, |
|
963 | 313 |
tycons = tycons, abbrs = abbrs, arities = arities}; |
416 | 314 |
|
315 |
val tsig0 = make_tsig ([], [], [], [], [], []); |
|
256 | 316 |
|
0 | 317 |
|
1215
a206f722bef9
added nonempty_sort (a somewhat braindead version!);
wenzelm
parents:
963
diff
changeset
|
318 |
|
a206f722bef9
added nonempty_sort (a somewhat braindead version!);
wenzelm
parents:
963
diff
changeset
|
319 |
|
416 | 320 |
(* typ_errors *) |
256 | 321 |
|
416 | 322 |
(*check validity of (not necessarily normal) type; accumulate error messages*) |
256 | 323 |
|
416 | 324 |
fun typ_errors tsig (typ, errors) = |
256 | 325 |
let |
963 | 326 |
val TySg {classes, tycons, abbrs, ...} = tsig; |
416 | 327 |
|
328 |
fun class_err (errs, c) = |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
329 |
if c mem_string classes then errs |
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
330 |
else undcl_class c ins_string errs; |
256 | 331 |
|
332 |
val sort_err = foldl class_err; |
|
0 | 333 |
|
256 | 334 |
fun typ_errs (Type (c, Us), errs) = |
335 |
let |
|
336 |
val errs' = foldr typ_errs (Us, errs); |
|
337 |
fun nargs n = |
|
338 |
if n = length Us then errs' |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
339 |
else ("Wrong number of arguments: " ^ quote c) ins_string errs'; |
256 | 340 |
in |
963 | 341 |
(case assoc (tycons, c) of |
256 | 342 |
Some n => nargs n |
343 |
| None => |
|
344 |
(case assoc (abbrs, c) of |
|
345 |
Some (vs, _) => nargs (length vs) |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
346 |
| None => undcl_type c ins_string errs)) |
256 | 347 |
end |
348 |
| typ_errs (TFree (_, S), errs) = sort_err (errs, S) |
|
416 | 349 |
| typ_errs (TVar ((x, i), S), errs) = |
350 |
if i < 0 then |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
351 |
("Negative index for TVar " ^ quote x) ins_string sort_err (errs, S) |
416 | 352 |
else sort_err (errs, S); |
256 | 353 |
in |
416 | 354 |
typ_errs (typ, errors) |
256 | 355 |
end; |
356 |
||
357 |
||
358 |
(* cert_typ *) |
|
359 |
||
2964 | 360 |
(*check and normalize typ wrt. tsig*) (*exception TYPE*) |
361 |
fun cert_typ tsig T = |
|
362 |
(case typ_errors tsig (T, []) of |
|
363 |
[] => norm_typ tsig T |
|
364 |
| errs => raise_type (cat_lines errs) [T] []); |
|
256 | 365 |
|
366 |
||
367 |
||
422 | 368 |
(** merge type signatures **) |
256 | 369 |
|
422 | 370 |
(*'assoc_union' merges two association lists if the contents associated |
371 |
the keys are lists*) |
|
0 | 372 |
|
422 | 373 |
fun assoc_union (as1, []) = as1 |
374 |
| assoc_union (as1, (key, l2) :: as2) = |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
375 |
(case assoc_string (as1, key) of |
2964 | 376 |
Some l1 => assoc_union |
377 |
(overwrite (as1, (key, l1 union_string l2)), as2) |
|
422 | 378 |
| None => assoc_union ((key, l2) :: as1, as2)); |
0 | 379 |
|
380 |
||
2964 | 381 |
(* merge classrel *) |
0 | 382 |
|
2964 | 383 |
fun merge_classrel (classrel1, classrel2) = |
384 |
let val classrel = transitive_closure (assoc_union (classrel1, classrel2)) |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
385 |
in |
2964 | 386 |
if exists (op mem_string) classrel then |
422 | 387 |
error ("Cyclic class structure!") (* FIXME improve msg, raise TERM *) |
2964 | 388 |
else classrel |
416 | 389 |
end; |
390 |
||
391 |
||
422 | 392 |
(* coregularity *) |
0 | 393 |
|
394 |
(* 'is_unique_decl' checks if there exists just one declaration t:(Ss)C *) |
|
395 |
||
963 | 396 |
fun is_unique_decl ars (t,(C,w)) = case assoc (ars, C) of |
0 | 397 |
Some(w1) => if w = w1 then () else |
256 | 398 |
error("There are two declarations\n" ^ |
2964 | 399 |
Sorts.str_of_arity(t, w, [C]) ^ " and\n" ^ |
400 |
Sorts.str_of_arity(t, w1, [C]) ^ "\n" ^ |
|
0 | 401 |
"with the same result class.") |
402 |
| None => (); |
|
403 |
||
963 | 404 |
(* 'coreg' checks if there are two declarations t:(Ss1)C1 and t:(Ss2)C2 |
0 | 405 |
such that C1 >= C2 then Ss1 >= Ss2 (elementwise) *) |
406 |
||
963 | 407 |
fun coreg_err(t, (C1,w1), (C2,w2)) = |
2964 | 408 |
error("Declarations " ^ Sorts.str_of_arity(t, w1, [C1]) ^ " and " |
409 |
^ Sorts.str_of_arity(t, w2, [C2]) ^ " are in conflict"); |
|
0 | 410 |
|
2964 | 411 |
fun coreg classrel (t, Cw1) = |
412 |
let |
|
413 |
fun check1(Cw1 as (C1,w1), Cw2 as (C2,w2)) = |
|
414 |
if leq classrel (C1,C2) then |
|
415 |
if Sorts.sorts_le classrel (w1,w2) then () |
|
416 |
else coreg_err(t, Cw1, Cw2) |
|
417 |
else () |
|
418 |
fun check(Cw2) = (check1(Cw1,Cw2); check1(Cw2,Cw1)) |
|
963 | 419 |
in seq check end; |
0 | 420 |
|
2964 | 421 |
fun add_arity classrel ars (tCw as (_,Cw)) = |
422 |
(is_unique_decl ars tCw; coreg classrel tCw ars; Cw ins ars); |
|
0 | 423 |
|
256 | 424 |
fun varying_decls t = |
425 |
error ("Type constructor " ^ quote t ^ " has varying number of arguments"); |
|
0 | 426 |
|
427 |
||
963 | 428 |
(* 'merge_arities' builds the union of two 'arities' lists; |
422 | 429 |
it only checks the two restriction conditions and inserts afterwards |
430 |
all elements of the second list into the first one *) |
|
431 |
||
2964 | 432 |
fun merge_arities classrel = |
433 |
let fun test_ar t (ars1, sw) = add_arity classrel ars1 (t,sw); |
|
422 | 434 |
|
963 | 435 |
fun merge_c (arities1, (c as (t, ars2))) = case assoc (arities1, t) of |
436 |
Some(ars1) => |
|
437 |
let val ars = foldl (test_ar t) (ars1, ars2) |
|
438 |
in overwrite (arities1, (t,ars)) end |
|
439 |
| None => c::arities1 |
|
422 | 440 |
in foldl merge_c end; |
441 |
||
963 | 442 |
fun add_tycons (tycons, tn as (t,n)) = |
443 |
(case assoc (tycons, t) of |
|
444 |
Some m => if m = n then tycons else varying_decls t |
|
445 |
| None => tn :: tycons); |
|
422 | 446 |
|
447 |
fun merge_abbrs (abbrs1, abbrs2) = |
|
621 | 448 |
let val abbrs = abbrs1 union abbrs2 in |
449 |
(case gen_duplicates eq_fst abbrs of |
|
422 | 450 |
[] => abbrs |
621 | 451 |
| dups => raise_term (dup_tyabbrs (map fst dups)) []) |
422 | 452 |
end; |
453 |
||
454 |
||
455 |
(* 'merge_tsigs' takes the above declared functions to merge two type |
|
456 |
signatures *) |
|
457 |
||
2964 | 458 |
fun merge_tsigs(TySg{classes=classes1, default=default1, classrel=classrel1, |
963 | 459 |
tycons=tycons1, arities=arities1, abbrs=abbrs1}, |
2964 | 460 |
TySg{classes=classes2, default=default2, classrel=classrel2, |
963 | 461 |
tycons=tycons2, arities=arities2, abbrs=abbrs2}) = |
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
462 |
let val classes' = classes1 union_string classes2; |
2964 | 463 |
val classrel' = merge_classrel (classrel1, classrel2); |
963 | 464 |
val tycons' = foldl add_tycons (tycons1, tycons2) |
2964 | 465 |
val arities' = merge_arities classrel' (arities1, arities2); |
466 |
val default' = Sorts.norm_sort classrel' (default1 @ default2); |
|
422 | 467 |
val abbrs' = merge_abbrs(abbrs1, abbrs2); |
2964 | 468 |
in make_tsig(classes', classrel', default', tycons', abbrs', arities') end; |
422 | 469 |
|
470 |
||
471 |
||
472 |
(*** extend type signatures ***) |
|
473 |
||
2964 | 474 |
(** add classes and classrel relations **) |
422 | 475 |
|
476 |
fun add_classes classes cs = |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
477 |
(case cs inter_string classes of |
422 | 478 |
[] => cs @ classes |
479 |
| dups => err_dup_classes cs); |
|
480 |
||
481 |
||
2964 | 482 |
(*'add_classrel' adds a tuple consisting of a new class (the new class has |
422 | 483 |
already been inserted into the 'classes' list) and its superclasses (they |
2964 | 484 |
must be declared in 'classes' too) to the 'classrel' list of the given type |
422 | 485 |
signature; furthermore all inherited superclasses according to the |
486 |
superclasses brought with are inserted and there is a check that there are |
|
487 |
no cycles (i.e. C <= D <= C, with C <> D);*) |
|
488 |
||
2964 | 489 |
fun add_classrel classes (classrel, (s, ges)) = |
621 | 490 |
let |
2964 | 491 |
fun upd (classrel, s') = |
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
492 |
if s' mem_string classes then |
2964 | 493 |
let val ges' = the (assoc (classrel, s)) |
494 |
in case assoc (classrel, s') of |
|
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
495 |
Some sups => if s mem_string sups |
422 | 496 |
then error(" Cycle :" ^ s^" <= "^ s'^" <= "^ s ) |
2964 | 497 |
else overwrite |
498 |
(classrel, (s, sups union_string ges')) |
|
499 |
| None => classrel |
|
621 | 500 |
end |
501 |
else err_undcl_class s' |
|
2964 | 502 |
in foldl upd (classrel @ [(s, ges)], ges) end; |
422 | 503 |
|
504 |
||
505 |
(* 'extend_classes' inserts all new classes into the corresponding |
|
2964 | 506 |
lists ('classes', 'classrel') if possible *) |
422 | 507 |
|
2964 | 508 |
fun extend_classes (classes, classrel, new_classes) = |
621 | 509 |
let |
510 |
val classes' = add_classes classes (map fst new_classes); |
|
2964 | 511 |
val classrel' = foldl (add_classrel classes') (classrel, new_classes); |
512 |
in (classes', classrel') end; |
|
422 | 513 |
|
514 |
||
621 | 515 |
(* ext_tsig_classes *) |
516 |
||
517 |
fun ext_tsig_classes tsig new_classes = |
|
518 |
let |
|
2964 | 519 |
val TySg {classes, classrel, default, tycons, abbrs, arities} = tsig; |
520 |
val (classes',classrel') = extend_classes (classes,classrel,new_classes); |
|
621 | 521 |
in |
2964 | 522 |
make_tsig (classes', classrel', default, tycons, abbrs, arities) |
621 | 523 |
end; |
524 |
||
525 |
||
2964 | 526 |
(* ext_tsig_classrel *) |
422 | 527 |
|
2964 | 528 |
fun ext_tsig_classrel tsig pairs = |
422 | 529 |
let |
2964 | 530 |
val TySg {classes, classrel, default, tycons, abbrs, arities} = tsig; |
422 | 531 |
|
532 |
(* FIXME clean! *) |
|
2964 | 533 |
val classrel' = |
534 |
merge_classrel (classrel, map (fn (c1, c2) => (c1, [c2])) pairs); |
|
422 | 535 |
in |
2964 | 536 |
make_tsig (classes, classrel', default, tycons, abbrs, arities) |
422 | 537 |
end; |
538 |
||
539 |
||
540 |
(* ext_tsig_defsort *) |
|
541 |
||
2964 | 542 |
fun ext_tsig_defsort(TySg{classes,classrel,tycons,abbrs,arities,...}) default = |
543 |
make_tsig (classes, classrel, default, tycons, abbrs, arities); |
|
422 | 544 |
|
545 |
||
546 |
||
621 | 547 |
(** add types **) |
582 | 548 |
|
2964 | 549 |
fun ext_tsig_types (TySg {classes, classrel, default, tycons, abbrs, arities}) ts = |
582 | 550 |
let |
551 |
fun check_type (c, n) = |
|
552 |
if n < 0 then err_neg_args c |
|
963 | 553 |
else if is_some (assoc (tycons, c)) then err_dup_tycon c |
2233
f919bdd5f9b6
Removed or eta-expanded some declarations that are illegal under value
paulson
parents:
2182
diff
changeset
|
554 |
else if is_some (assoc (abbrs, c)) then error (ty_confl c) |
582 | 555 |
else (); |
556 |
in |
|
557 |
seq check_type ts; |
|
2964 | 558 |
make_tsig (classes, classrel, default, ts @ tycons, abbrs, |
963 | 559 |
map (rpair [] o #1) ts @ arities) |
582 | 560 |
end; |
561 |
||
562 |
||
563 |
||
564 |
(** add type abbreviations **) |
|
565 |
||
566 |
fun abbr_errors tsig (a, (lhs_vs, rhs)) = |
|
567 |
let |
|
963 | 568 |
val TySg {tycons, abbrs, ...} = tsig; |
621 | 569 |
val rhs_vs = map (#1 o #1) (typ_tvars rhs); |
582 | 570 |
|
571 |
val dup_lhs_vars = |
|
572 |
(case duplicates lhs_vs of |
|
573 |
[] => [] |
|
621 | 574 |
| vs => ["Duplicate variables on lhs: " ^ commas_quote vs]); |
582 | 575 |
|
576 |
val extra_rhs_vars = |
|
577 |
(case gen_rems (op =) (rhs_vs, lhs_vs) of |
|
578 |
[] => [] |
|
621 | 579 |
| vs => ["Extra variables on rhs: " ^ commas_quote vs]); |
582 | 580 |
|
581 |
val tycon_confl = |
|
963 | 582 |
if is_none (assoc (tycons, a)) then [] |
582 | 583 |
else [ty_confl a]; |
584 |
||
585 |
val dup_abbr = |
|
586 |
if is_none (assoc (abbrs, a)) then [] |
|
587 |
else ["Duplicate declaration of abbreviation"]; |
|
588 |
in |
|
589 |
dup_lhs_vars @ extra_rhs_vars @ tycon_confl @ dup_abbr @ |
|
590 |
typ_errors tsig (rhs, []) |
|
591 |
end; |
|
592 |
||
621 | 593 |
fun prep_abbr tsig (a, vs, raw_rhs) = |
594 |
let |
|
595 |
fun err msgs = (seq writeln msgs; |
|
596 |
error ("The error(s) above occurred in type abbreviation " ^ quote a)); |
|
597 |
||
598 |
val rhs = rem_sorts (varifyT (no_tvars raw_rhs)) |
|
599 |
handle TYPE (msg, _, _) => err [msg]; |
|
600 |
val abbr = (a, (vs, rhs)); |
|
601 |
in |
|
582 | 602 |
(case abbr_errors tsig abbr of |
621 | 603 |
[] => abbr |
604 |
| msgs => err msgs) |
|
582 | 605 |
end; |
606 |
||
2964 | 607 |
fun add_abbr (tsig as TySg{classes,classrel,default,tycons,arities,abbrs}, |
963 | 608 |
abbr) = |
621 | 609 |
make_tsig |
2964 | 610 |
(classes,classrel,default,tycons, prep_abbr tsig abbr :: abbrs, arities); |
621 | 611 |
|
612 |
fun ext_tsig_abbrs tsig raw_abbrs = foldl add_abbr (tsig, raw_abbrs); |
|
582 | 613 |
|
614 |
||
615 |
||
422 | 616 |
(** add arities **) |
617 |
||
0 | 618 |
(* 'coregular' checks |
963 | 619 |
- the two restrictions 'is_unique_decl' and 'coreg' |
256 | 620 |
- if the classes in the new type declarations are known in the |
0 | 621 |
given type signature |
622 |
- if one type constructor has always the same number of arguments; |
|
256 | 623 |
if one type declaration has passed all checks it is inserted into |
963 | 624 |
the 'arities' association list of the given type signatrure *) |
0 | 625 |
|
2964 | 626 |
fun coregular (classes, classrel, tycons) = |
2182
29e56f003599
Removal of polymorphic equality via mem, subset, eq_set, etc
paulson
parents:
2148
diff
changeset
|
627 |
let fun ex C = if C mem_string classes then () else err_undcl_class(C); |
0 | 628 |
|
963 | 629 |
fun addar(arities, (t, (w, C))) = case assoc(tycons, t) of |
0 | 630 |
Some(n) => if n <> length w then varying_decls(t) else |
963 | 631 |
((seq o seq) ex w; ex C; |
632 |
let val ars = the (assoc(arities, t)) |
|
2964 | 633 |
val ars' = add_arity classrel ars (t,(C,w)) |
963 | 634 |
in overwrite(arities, (t,ars')) end) |
2233
f919bdd5f9b6
Removed or eta-expanded some declarations that are illegal under value
paulson
parents:
2182
diff
changeset
|
635 |
| None => error (undcl_type t); |
0 | 636 |
|
963 | 637 |
in addar end; |
0 | 638 |
|
639 |
||
963 | 640 |
(* 'close' extends the 'arities' association list after all new type |
0 | 641 |
declarations have been inserted successfully: |
642 |
for every declaration t:(Ss)C , for all classses D with C <= D: |
|
643 |
if there is no declaration t:(Ss')C' with C < C' and C' <= D |
|
963 | 644 |
then insert the declaration t:(Ss)D into 'arities' |
0 | 645 |
this means, if there exists a declaration t:(Ss)C and there is |
646 |
no declaration t:(Ss')D with C <=D then the declaration holds |
|
256 | 647 |
for all range classes more general than C *) |
648 |
||
2964 | 649 |
fun close classrel arities = |
650 |
let fun check sl (l, (s, dom)) = case assoc (classrel, s) of |
|
621 | 651 |
Some sups => |
256 | 652 |
let fun close_sup (l, sup) = |
2964 | 653 |
if exists (fn s'' => less classrel (s, s'') andalso |
654 |
leq classrel (s'', sup)) sl |
|
0 | 655 |
then l |
256 | 656 |
else (sup, dom)::l |
657 |
in foldl close_sup (l, sups) end |
|
0 | 658 |
| None => l; |
256 | 659 |
fun ext (s, l) = (s, foldl (check (map #1 l)) (l, l)); |
963 | 660 |
in map ext arities end; |
0 | 661 |
|
422 | 662 |
|
621 | 663 |
(* ext_tsig_arities *) |
256 | 664 |
|
2964 | 665 |
fun norm_domain classrel = |
666 |
let fun one_min (f, (doms, ran)) = (f, (map (Sorts.norm_sort classrel) doms, ran)) |
|
667 |
in map one_min end; |
|
668 |
||
621 | 669 |
fun ext_tsig_arities tsig sarities = |
416 | 670 |
let |
2964 | 671 |
val TySg {classes, classrel, default, tycons, arities, abbrs} = tsig; |
963 | 672 |
val arities1 = |
2964 | 673 |
List.concat |
2672
85d7e800d754
Replaced "flat" by the Basis Library function List.concat
paulson
parents:
2617
diff
changeset
|
674 |
(map (fn (t, ss, cs) => map (fn c => (t, (ss, c))) cs) sarities); |
2964 | 675 |
val arities2 = foldl (coregular (classes, classrel, tycons)) |
676 |
(arities, norm_domain classrel arities1) |
|
677 |
|> close classrel; |
|
416 | 678 |
in |
2964 | 679 |
make_tsig (classes, classrel, default, tycons, abbrs, arities2) |
416 | 680 |
end; |
0 | 681 |
|
682 |
||
416 | 683 |
|
2964 | 684 |
(*** type unification and friends ***) |
0 | 685 |
|
2964 | 686 |
(** matching **) |
0 | 687 |
|
2964 | 688 |
exception TYPE_MATCH; |
0 | 689 |
|
2964 | 690 |
fun typ_match tsig = |
691 |
let |
|
692 |
fun match (subs, (TVar (v, S), T)) = |
|
693 |
(case assoc (subs, v) of |
|
694 |
None => ((v, (check_has_sort (tsig, T, S); T)) :: subs |
|
695 |
handle TYPE _ => raise TYPE_MATCH) |
|
696 |
| Some U => if U = T then subs else raise TYPE_MATCH) |
|
697 |
| match (subs, (Type (a, Ts), Type (b, Us))) = |
|
698 |
if a <> b then raise TYPE_MATCH |
|
699 |
else foldl match (subs, Ts ~~ Us) |
|
700 |
| match (subs, (TFree x, TFree y)) = |
|
701 |
if x = y then subs else raise TYPE_MATCH |
|
702 |
| match _ = raise TYPE_MATCH; |
|
703 |
in match end; |
|
0 | 704 |
|
2964 | 705 |
fun typ_instance (tsig, T, U) = |
706 |
(typ_match tsig ([], (U, T)); true) handle TYPE_MATCH => false; |
|
707 |
||
0 | 708 |
|
2964 | 709 |
|
710 |
(** unification **) |
|
711 |
||
0 | 712 |
exception TUNIFY; |
713 |
||
714 |
||
2964 | 715 |
(* occurs check *) |
0 | 716 |
|
2964 | 717 |
fun occurs v tye = |
718 |
let |
|
719 |
fun occ (Type (_, Ts)) = exists occ Ts |
|
720 |
| occ (TFree _) = false |
|
721 |
| occ (TVar (w, _)) = |
|
722 |
eq_ix (v, w) orelse |
|
723 |
(case assoc (tye, w) of |
|
724 |
None => false |
|
725 |
| Some U => occ U); |
|
0 | 726 |
in occ end; |
727 |
||
2964 | 728 |
|
729 |
(* chase variable assignments *) |
|
730 |
||
731 |
(*if devar returns a type var then it must be unassigned*) |
|
732 |
fun devar (T as TVar (v, _), tye) = |
|
733 |
(case assoc (tye, v) of |
|
734 |
Some U => devar (U, tye) |
|
735 |
| None => T) |
|
256 | 736 |
| devar (T, tye) = T; |
0 | 737 |
|
1627 | 738 |
|
2964 | 739 |
(* add_env *) |
0 | 740 |
|
2964 | 741 |
(*avoids chains 'a |-> 'b |-> 'c ...*) |
742 |
fun add_env (p, []) = [p] |
|
743 |
| add_env (vT as (v, T), (xU as (x, TVar (w, S))) :: ps) = |
|
744 |
(if eq_ix (v, w) then (x, T) else xU) :: add_env (vT, ps) |
|
745 |
| add_env (v, x :: xs) = x :: add_env (v, xs); |
|
0 | 746 |
|
747 |
||
2964 | 748 |
(* unify *) |
749 |
||
750 |
fun unify (tsig as TySg {classrel, arities, ...}) maxidx tyenv TU = |
|
751 |
let |
|
752 |
val tyvar_count = ref maxidx; |
|
753 |
fun gen_tyvar S = TVar (("'a", inc tyvar_count), S); |
|
754 |
||
755 |
fun mg_domain a S = |
|
756 |
Sorts.mg_domain classrel arities a S handle TYPE _ => raise TUNIFY; |
|
757 |
||
758 |
fun meet ((_, []), tye) = tye |
|
759 |
| meet ((TVar (xi, S'), S), tye) = |
|
760 |
if Sorts.sort_le classrel (S', S) then tye |
|
761 |
else add_env ((xi, gen_tyvar (Sorts.inter_sort classrel (S', S))), tye) |
|
762 |
| meet ((TFree (_, S'), S), tye) = |
|
763 |
if Sorts.sort_le classrel (S', S) then tye |
|
764 |
else raise TUNIFY |
|
765 |
| meet ((Type (a, Ts), S), tye) = meets ((Ts, mg_domain a S), tye) |
|
766 |
and meets (([], []), tye) = tye |
|
767 |
| meets ((T :: Ts, S :: Ss), tye) = |
|
768 |
meets ((Ts, Ss), meet ((devar (T, tye), S), tye)) |
|
769 |
| meets _ = sys_error "meets"; |
|
770 |
||
771 |
fun unif ((ty1, ty2), tye) = |
|
772 |
(case (devar (ty1, tye), devar (ty2, tye)) of |
|
773 |
(T as TVar (v, S1), U as TVar (w, S2)) => |
|
774 |
if eq_ix (v, w) then tye |
|
775 |
else if Sorts.sort_le classrel (S1, S2) then add_env ((w, T), tye) |
|
776 |
else if Sorts.sort_le classrel (S2, S1) then add_env ((v, U), tye) |
|
777 |
else |
|
778 |
let val S = gen_tyvar (Sorts.inter_sort classrel (S1, S2)) in |
|
779 |
add_env ((v, S), add_env ((w, S), tye)) |
|
780 |
end |
|
781 |
| (TVar (v, S), T) => |
|
782 |
if occurs v tye T then raise TUNIFY |
|
783 |
else meet ((T, S), add_env ((v, T), tye)) |
|
784 |
| (T, TVar (v, S)) => |
|
785 |
if occurs v tye T then raise TUNIFY |
|
786 |
else meet ((T, S), add_env ((v, T), tye)) |
|
787 |
| (Type (a, Ts), Type (b, Us)) => |
|
788 |
if a <> b then raise TUNIFY |
|
789 |
else foldr unif (Ts ~~ Us, tye) |
|
790 |
| (T, U) => if T = U then tye else raise TUNIFY); |
|
791 |
in |
|
792 |
(unif (TU, tyenv), ! tyvar_count) |
|
793 |
end; |
|
0 | 794 |
|
795 |
||
2964 | 796 |
(* raw_unify *) |
0 | 797 |
|
2964 | 798 |
(*purely structural unification -- ignores sorts*) |
450 | 799 |
fun raw_unify (ty1, ty2) = |
1435
aefcd255ed4a
Removed bug in type unification. Negative indexes are not used any longer.
nipkow
parents:
1392
diff
changeset
|
800 |
(unify tsig0 0 [] (rem_sorts ty1, rem_sorts ty2); true) |
450 | 801 |
handle TUNIFY => false; |
802 |
||
803 |
||
0 | 804 |
|
2964 | 805 |
(** type inference **) |
1435
aefcd255ed4a
Removed bug in type unification. Negative indexes are not used any longer.
nipkow
parents:
1392
diff
changeset
|
806 |
|
2964 | 807 |
(* constraints *) |
2587 | 808 |
|
809 |
fun get_sort tsig def_sort env xi = |
|
810 |
(case (assoc (env, xi), def_sort xi) of |
|
811 |
(None, None) => defaultS tsig |
|
812 |
| (None, Some S) => S |
|
813 |
| (Some S, None) => S |
|
814 |
| (Some S, Some S') => |
|
815 |
if eq_sort tsig (S, S') then S |
|
816 |
else error ("Sort constraint inconsistent with default for type variable " ^ |
|
817 |
quote (Syntax.string_of_vname' xi))); |
|
818 |
||
2964 | 819 |
fun constrain t T = |
820 |
if T = dummyT then t |
|
821 |
else Const ("_type_constraint_", T) $ t; |
|
0 | 822 |
|
823 |
||
2964 | 824 |
(* decode_types *) |
0 | 825 |
|
2964 | 826 |
(*transform parse tree into raw term (idempotent)*) |
827 |
fun decode_types tsig is_const def_type def_sort tm = |
|
828 |
let |
|
829 |
fun get_type xi = if_none (def_type xi) dummyT; |
|
830 |
val sort_env = Syntax.raw_term_sorts (eq_sort tsig) tm; |
|
831 |
||
832 |
fun decodeT t = |
|
833 |
cert_typ tsig (Syntax.typ_of_term (get_sort tsig def_sort sort_env) t); |
|
0 | 834 |
|
2964 | 835 |
fun decode (Const ("_constrain", _) $ t $ typ) = |
836 |
constrain (decode t) (decodeT typ) |
|
837 |
| decode (Const ("_constrainAbs", _) $ (abs as Abs (x, T, t)) $ typ) = |
|
838 |
if T = dummyT then Abs (x, decodeT typ, decode t) |
|
839 |
else constrain abs (decodeT typ --> dummyT) |
|
840 |
| decode (Abs (x, T, t)) = Abs (x, T, decode t) |
|
841 |
| decode (t $ u) = decode t $ decode u |
|
842 |
| decode (t as Free (x, T)) = |
|
843 |
if is_const x then Const (x, T) |
|
844 |
else if T = dummyT then Free (x, get_type (x, ~1)) |
|
845 |
else constrain t (get_type (x, ~1)) |
|
846 |
| decode (t as Var (xi, T)) = |
|
847 |
if T = dummyT then Var (xi, get_type xi) |
|
848 |
else constrain t (get_type xi) |
|
849 |
| decode (t as Bound _) = t |
|
850 |
| decode (t as Const _) = t; |
|
851 |
in |
|
852 |
decode tm |
|
853 |
end; |
|
0 | 854 |
|
855 |
||
2964 | 856 |
(* infer_types *) |
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
857 |
|
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
858 |
(* |
2964 | 859 |
Given [T1,...,Tn] and [t1,...,tn], ensure that the type of ti |
860 |
unifies with Ti (for i=1,...,n). |
|
861 |
||
862 |
tsig: type signature |
|
863 |
const_type: term signature |
|
864 |
def_type: partial map from indexnames to types (constrains Frees, Vars) |
|
865 |
def_sort: partial map from indexnames to sorts (constrains TFrees, TVars) |
|
866 |
used: list of already used type variables |
|
867 |
freeze: if true then generated parameters are turned into TFrees, else TVars |
|
949
83c588d6fee9
Changed treatment of during type inference internally generated type
nipkow
parents:
621
diff
changeset
|
868 |
*) |
0 | 869 |
|
2964 | 870 |
(*user-supplied inference parameters*) |
871 |
fun q_is_param (x, _) = |
|
872 |
(case explode x of |
|
873 |
"?" :: _ => true |
|
874 |
| _ => false); |
|
0 | 875 |
|
2979 | 876 |
fun infer_types prt prT tsig const_type def_type def_sort used freeze pat_Ts raw_ts = |
565 | 877 |
let |
2964 | 878 |
val TySg {classrel, arities, ...} = tsig; |
879 |
val pat_Ts' = map (cert_typ tsig) pat_Ts; |
|
880 |
val raw_ts' = |
|
881 |
map (decode_types tsig (is_some o const_type) def_type def_sort) raw_ts; |
|
882 |
val (ts, Ts, unifier) = |
|
2979 | 883 |
TypeInfer.infer_types prt prT const_type classrel arities used freeze |
2964 | 884 |
q_is_param raw_ts' pat_Ts'; |
565 | 885 |
in |
2964 | 886 |
(ts, unifier) |
565 | 887 |
end; |
0 | 888 |
|
889 |
end; |