author | wenzelm |
Tue, 06 Jun 2006 20:47:12 +0200 | |
changeset 19800 | 5f764272183e |
parent 19422 | bba26da0f227 |
child 19861 | 620d90091788 |
permissions | -rw-r--r-- |
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
1 |
(* Title: Pure/envir.ML |
0 | 2 |
ID: $Id$ |
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1988 University of Cambridge |
10485 | 5 |
|
15797 | 6 |
Environments. The type of a term variable / sort of a type variable is |
7 |
part of its name. The lookup function must apply type substitutions, |
|
8 |
since they may change the identity of a variable. |
|
0 | 9 |
*) |
10 |
||
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
11 |
signature ENVIR = |
0 | 12 |
sig |
15797 | 13 |
type tenv |
14 |
datatype env = Envir of {asol: tenv, iTs: Type.tyenv, maxidx: int} |
|
15 |
val type_env: env -> Type.tyenv |
|
11513 | 16 |
exception SAME |
10485 | 17 |
val genvars: string -> env * typ list -> env * term list |
18 |
val genvar: string -> env * typ -> env * term |
|
15797 | 19 |
val lookup: env * (indexname * typ) -> term option |
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
20 |
val lookup': tenv * (indexname * typ) -> term option |
15797 | 21 |
val update: ((indexname * typ) * term) * env -> env |
10485 | 22 |
val empty: int -> env |
23 |
val is_empty: env -> bool |
|
24 |
val above: int * env -> bool |
|
15797 | 25 |
val vupdate: ((indexname * typ) * term) * env -> env |
26 |
val alist_of: env -> (indexname * (typ * term)) list |
|
10485 | 27 |
val norm_term: env -> term -> term |
11513 | 28 |
val norm_term_same: env -> term -> term |
15797 | 29 |
val norm_type: Type.tyenv -> typ -> typ |
30 |
val norm_type_same: Type.tyenv -> typ -> typ |
|
31 |
val norm_types_same: Type.tyenv -> typ list -> typ list |
|
10485 | 32 |
val beta_norm: term -> term |
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
33 |
val head_norm: env -> term -> term |
18937 | 34 |
val eta_contract: term -> term |
35 |
val beta_eta_contract: term -> term |
|
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
36 |
val fastype: env -> typ list -> term -> typ |
15797 | 37 |
val typ_subst_TVars: Type.tyenv -> typ -> typ |
38 |
val subst_TVars: Type.tyenv -> term -> term |
|
39 |
val subst_Vars: tenv -> term -> term |
|
40 |
val subst_vars: Type.tyenv * tenv -> term -> term |
|
19422 | 41 |
val expand_atom: typ -> typ * term -> term |
0 | 42 |
end; |
43 |
||
1500 | 44 |
structure Envir : ENVIR = |
0 | 45 |
struct |
46 |
||
47 |
(*updating can destroy environment in 2 ways!! |
|
48 |
(1) variables out of range (2) circular assignments |
|
49 |
*) |
|
15797 | 50 |
type tenv = (typ * term) Vartab.table |
51 |
||
0 | 52 |
datatype env = Envir of |
15797 | 53 |
{maxidx: int, (*maximum index of vars*) |
54 |
asol: tenv, (*table of assignments to Vars*) |
|
55 |
iTs: Type.tyenv} (*table of assignments to TVars*) |
|
0 | 56 |
|
12496 | 57 |
fun type_env (Envir {iTs, ...}) = iTs; |
0 | 58 |
|
59 |
(*Generate a list of distinct variables. |
|
60 |
Increments index to make them distinct from ALL present variables. *) |
|
61 |
fun genvars name (Envir{maxidx, asol, iTs}, Ts) : env * term list = |
|
62 |
let fun genvs (_, [] : typ list) : term list = [] |
|
63 |
| genvs (n, [T]) = [ Var((name, maxidx+1), T) ] |
|
64 |
| genvs (n, T::Ts) = |
|
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
65 |
Var((name ^ radixstring(26,"a",n), maxidx+1), T) |
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
66 |
:: genvs(n+1,Ts) |
0 | 67 |
in (Envir{maxidx=maxidx+1, asol=asol, iTs=iTs}, genvs (0,Ts)) end; |
68 |
||
69 |
(*Generate a variable.*) |
|
70 |
fun genvar name (env,T) : env * term = |
|
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
71 |
let val (env',[v]) = genvars name (env,[T]) |
0 | 72 |
in (env',v) end; |
73 |
||
15797 | 74 |
fun var_clash ixn T T' = raise TYPE ("Variable " ^ |
75 |
quote (Syntax.string_of_vname ixn) ^ " has two distinct types", |
|
76 |
[T', T], []); |
|
0 | 77 |
|
15797 | 78 |
fun gen_lookup f asol (xname, T) = |
17412 | 79 |
(case Vartab.lookup asol xname of |
15797 | 80 |
NONE => NONE |
81 |
| SOME (U, t) => if f (T, U) then SOME t |
|
82 |
else var_clash xname T U); |
|
83 |
||
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
84 |
(* When dealing with environments produced by matching instead *) |
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
85 |
(* of unification, there is no need to chase assigned TVars. *) |
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
86 |
(* In this case, we can simply ignore the type substitution *) |
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
87 |
(* and use = instead of eq_type. *) |
15797 | 88 |
|
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
89 |
fun lookup' (asol, p) = gen_lookup op = asol p; |
15797 | 90 |
|
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
91 |
fun lookup2 (iTs, asol) p = |
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
92 |
if Vartab.is_empty iTs then lookup' (asol, p) |
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
93 |
else gen_lookup (Type.eq_type iTs) asol p; |
15797 | 94 |
|
95 |
fun lookup (Envir {asol, iTs, ...}, p) = lookup2 (iTs, asol) p; |
|
96 |
||
97 |
fun update (((xname, T), t), Envir {maxidx, asol, iTs}) = |
|
17412 | 98 |
Envir{maxidx=maxidx, asol=Vartab.update_new (xname, (T, t)) asol, iTs=iTs}; |
0 | 99 |
|
5289 | 100 |
(*The empty environment. New variables will start with the given index+1.*) |
8407
d522ad1809e9
Envir now uses Vartab instead of association lists.
berghofe
parents:
5289
diff
changeset
|
101 |
fun empty m = Envir{maxidx=m, asol=Vartab.empty, iTs=Vartab.empty}; |
0 | 102 |
|
2142
20f208ff085d
Deleted Olist constructor. Replaced minidx by "above" function
paulson
parents:
1500
diff
changeset
|
103 |
(*Test for empty environment*) |
8407
d522ad1809e9
Envir now uses Vartab instead of association lists.
berghofe
parents:
5289
diff
changeset
|
104 |
fun is_empty (Envir {asol, iTs, ...}) = Vartab.is_empty asol andalso Vartab.is_empty iTs; |
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
105 |
|
2142
20f208ff085d
Deleted Olist constructor. Replaced minidx by "above" function
paulson
parents:
1500
diff
changeset
|
106 |
(*Determine if the least index updated exceeds lim*) |
8407
d522ad1809e9
Envir now uses Vartab instead of association lists.
berghofe
parents:
5289
diff
changeset
|
107 |
fun above (lim, Envir {asol, iTs, ...}) = |
d522ad1809e9
Envir now uses Vartab instead of association lists.
berghofe
parents:
5289
diff
changeset
|
108 |
(case (Vartab.min_key asol, Vartab.min_key iTs) of |
15531 | 109 |
(NONE, NONE) => true |
110 |
| (SOME (_, i), NONE) => i > lim |
|
111 |
| (NONE, SOME (_, i')) => i' > lim |
|
112 |
| (SOME (_, i), SOME (_, i')) => i > lim andalso i' > lim); |
|
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
113 |
|
0 | 114 |
(*Update, checking Var-Var assignments: try to suppress higher indexes*) |
15797 | 115 |
fun vupdate ((aU as (a, U), t), env as Envir {iTs, ...}) = case t of |
116 |
Var (nT as (name', T)) => |
|
117 |
if a = name' then env (*cycle!*) |
|
247
bc10568855ee
added is_empty: env -> bool, minidx: env -> int option;
wenzelm
parents:
0
diff
changeset
|
118 |
else if xless(a, name') then |
15797 | 119 |
(case lookup (env, nT) of (*if already assigned, chase*) |
120 |
NONE => update ((nT, Var (a, T)), env) |
|
121 |
| SOME u => vupdate ((aU, u), env)) |
|
122 |
else update ((aU, t), env) |
|
123 |
| _ => update ((aU, t), env); |
|
0 | 124 |
|
125 |
||
126 |
(*Convert environment to alist*) |
|
8407
d522ad1809e9
Envir now uses Vartab instead of association lists.
berghofe
parents:
5289
diff
changeset
|
127 |
fun alist_of (Envir{asol,...}) = Vartab.dest asol; |
0 | 128 |
|
129 |
||
1500 | 130 |
(*** Beta normal form for terms (not eta normal form). |
131 |
Chases variables in env; Does not exploit sharing of variable bindings |
|
132 |
Does not check types, so could loop. ***) |
|
133 |
||
134 |
(*raised when norm has no effect on a term, to do sharing instead of copying*) |
|
135 |
exception SAME; |
|
0 | 136 |
|
11513 | 137 |
fun norm_term1 same (asol,t) : term = |
15797 | 138 |
let fun norm (Var wT) = |
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
139 |
(case lookup' (asol, wT) of |
15531 | 140 |
SOME u => (norm u handle SAME => u) |
141 |
| NONE => raise SAME) |
|
10485 | 142 |
| norm (Abs(a,T,body)) = Abs(a, T, norm body) |
143 |
| norm (Abs(_,_,body) $ t) = normh(subst_bound (t, body)) |
|
144 |
| norm (f $ t) = |
|
145 |
((case norm f of |
|
146 |
Abs(_,_,body) => normh(subst_bound (t, body)) |
|
147 |
| nf => nf $ (norm t handle SAME => t)) |
|
148 |
handle SAME => f $ norm t) |
|
149 |
| norm _ = raise SAME |
|
2191 | 150 |
and normh t = norm t handle SAME => t |
11513 | 151 |
in (if same then norm else normh) t end |
0 | 152 |
|
11513 | 153 |
fun normT iTs (Type (a, Ts)) = Type (a, normTs iTs Ts) |
154 |
| normT iTs (TFree _) = raise SAME |
|
15797 | 155 |
| normT iTs (TVar vS) = (case Type.lookup (iTs, vS) of |
15531 | 156 |
SOME U => normTh iTs U |
157 |
| NONE => raise SAME) |
|
11513 | 158 |
and normTh iTs T = ((normT iTs T) handle SAME => T) |
159 |
and normTs iTs [] = raise SAME |
|
160 |
| normTs iTs (T :: Ts) = |
|
161 |
((normT iTs T :: (normTs iTs Ts handle SAME => Ts)) |
|
162 |
handle SAME => T :: normTs iTs Ts); |
|
163 |
||
164 |
fun norm_term2 same (asol, iTs, t) : term = |
|
165 |
let fun norm (Const (a, T)) = Const(a, normT iTs T) |
|
166 |
| norm (Free (a, T)) = Free(a, normT iTs T) |
|
167 |
| norm (Var (w, T)) = |
|
15797 | 168 |
(case lookup2 (iTs, asol) (w, T) of |
15531 | 169 |
SOME u => normh u |
170 |
| NONE => Var(w, normT iTs T)) |
|
11513 | 171 |
| norm (Abs (a, T, body)) = |
172 |
(Abs (a, normT iTs T, normh body) handle SAME => Abs (a, T, norm body)) |
|
173 |
| norm (Abs(_, _, body) $ t) = normh (subst_bound (t, body)) |
|
174 |
| norm (f $ t) = |
|
10485 | 175 |
((case norm f of |
11513 | 176 |
Abs(_, _, body) => normh (subst_bound (t, body)) |
10485 | 177 |
| nf => nf $ normh t) |
178 |
handle SAME => f $ norm t) |
|
179 |
| norm _ = raise SAME |
|
1500 | 180 |
and normh t = (norm t) handle SAME => t |
11513 | 181 |
in (if same then norm else normh) t end; |
0 | 182 |
|
11513 | 183 |
fun gen_norm_term same (env as Envir{asol,iTs,...}) t : term = |
184 |
if Vartab.is_empty iTs then norm_term1 same (asol, t) |
|
185 |
else norm_term2 same (asol, iTs, t); |
|
186 |
||
187 |
val norm_term = gen_norm_term false; |
|
188 |
val norm_term_same = gen_norm_term true; |
|
10485 | 189 |
|
190 |
val beta_norm = norm_term (empty 0); |
|
719
e3e1d1a6d408
Pure/envir/norm_term: replaced equality test for [] by null
lcp
parents:
247
diff
changeset
|
191 |
|
12496 | 192 |
fun norm_type iTs = normTh iTs; |
193 |
fun norm_type_same iTs = |
|
11513 | 194 |
if Vartab.is_empty iTs then raise SAME else normT iTs; |
195 |
||
12496 | 196 |
fun norm_types_same iTs = |
11513 | 197 |
if Vartab.is_empty iTs then raise SAME else normTs iTs; |
198 |
||
199 |
||
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
200 |
(*Put a term into head normal form for unification.*) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
201 |
|
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
202 |
fun head_norm env t = |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
203 |
let |
15797 | 204 |
fun hnorm (Var vT) = (case lookup (env, vT) of |
15531 | 205 |
SOME u => head_norm env u |
206 |
| NONE => raise SAME) |
|
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
207 |
| hnorm (Abs (a, T, body)) = Abs (a, T, hnorm body) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
208 |
| hnorm (Abs (_, _, body) $ t) = |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
209 |
head_norm env (subst_bound (t, body)) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
210 |
| hnorm (f $ t) = (case hnorm f of |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
211 |
Abs (_, _, body) => head_norm env (subst_bound (t, body)) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
212 |
| nf => nf $ t) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
213 |
| hnorm _ = raise SAME |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
214 |
in hnorm t handle SAME => t end; |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
215 |
|
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
216 |
|
18937 | 217 |
(*Eta-contract a term (fully)*) |
218 |
||
219 |
fun eta_contract t = |
|
220 |
let |
|
221 |
exception SAME; |
|
222 |
fun eta (Abs (a, T, body)) = |
|
223 |
((case eta body of |
|
224 |
body' as (f $ Bound 0) => |
|
225 |
if loose_bvar1 (f, 0) then Abs(a, T, body') |
|
226 |
else incr_boundvars ~1 f |
|
227 |
| body' => Abs (a, T, body')) handle SAME => |
|
228 |
(case body of |
|
229 |
(f $ Bound 0) => |
|
230 |
if loose_bvar1 (f, 0) then raise SAME |
|
231 |
else incr_boundvars ~1 f |
|
232 |
| _ => raise SAME)) |
|
233 |
| eta (f $ t) = |
|
234 |
(let val f' = eta f |
|
235 |
in f' $ etah t end handle SAME => f $ eta t) |
|
236 |
| eta _ = raise SAME |
|
237 |
and etah t = (eta t handle SAME => t) |
|
238 |
in etah t end; |
|
239 |
||
240 |
val beta_eta_contract = eta_contract o beta_norm; |
|
241 |
||
242 |
||
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
243 |
(*finds type of term without checking that combinations are consistent |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
244 |
Ts holds types of bound variables*) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
245 |
fun fastype (Envir {iTs, ...}) = |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
246 |
let val funerr = "fastype: expected function type"; |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
247 |
fun fast Ts (f $ u) = |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
248 |
(case fast Ts f of |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
249 |
Type ("fun", [_, T]) => T |
15797 | 250 |
| TVar ixnS => |
251 |
(case Type.lookup (iTs, ixnS) of |
|
15531 | 252 |
SOME (Type ("fun", [_, T])) => T |
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
253 |
| _ => raise TERM (funerr, [f $ u])) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
254 |
| _ => raise TERM (funerr, [f $ u])) |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
255 |
| fast Ts (Const (_, T)) = T |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
256 |
| fast Ts (Free (_, T)) = T |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
257 |
| fast Ts (Bound i) = |
15570 | 258 |
(List.nth (Ts, i) |
259 |
handle Subscript => raise TERM ("fastype: Bound", [Bound i])) |
|
12231
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
260 |
| fast Ts (Var (_, T)) = T |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
261 |
| fast Ts (Abs (_, T, u)) = T --> fast (T :: Ts) u |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
262 |
in fast end; |
4a25f04bea61
Moved head_norm and fastype from unify.ML to envir.ML
berghofe
parents:
11513
diff
changeset
|
263 |
|
15797 | 264 |
|
265 |
(*Substitute for type Vars in a type*) |
|
266 |
fun typ_subst_TVars iTs T = if Vartab.is_empty iTs then T else |
|
267 |
let fun subst(Type(a, Ts)) = Type(a, map subst Ts) |
|
268 |
| subst(T as TFree _) = T |
|
269 |
| subst(T as TVar ixnS) = |
|
270 |
(case Type.lookup (iTs, ixnS) of NONE => T | SOME(U) => U) |
|
271 |
in subst T end; |
|
272 |
||
273 |
(*Substitute for type Vars in a term*) |
|
274 |
val subst_TVars = map_term_types o typ_subst_TVars; |
|
275 |
||
276 |
(*Substitute for Vars in a term *) |
|
277 |
fun subst_Vars itms t = if Vartab.is_empty itms then t else |
|
18937 | 278 |
let fun subst (v as Var ixnT) = the_default v (lookup' (itms, ixnT)) |
15797 | 279 |
| subst (Abs (a, T, t)) = Abs (a, T, subst t) |
280 |
| subst (f $ t) = subst f $ subst t |
|
281 |
| subst t = t |
|
282 |
in subst t end; |
|
283 |
||
284 |
(*Substitute for type/term Vars in a term *) |
|
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
285 |
fun subst_vars (iTs, itms) = |
15797 | 286 |
if Vartab.is_empty iTs then subst_Vars itms else |
287 |
let fun subst (Const (a, T)) = Const(a, typ_subst_TVars iTs T) |
|
288 |
| subst (Free (a, T)) = Free (a, typ_subst_TVars iTs T) |
|
16652
4ecf94235ec7
Fixed bug: lookup' must use = instead of eq_type to compare types of
berghofe
parents:
15797
diff
changeset
|
289 |
| subst (Var (ixn, T)) = (case lookup' (itms, (ixn, T)) of |
15797 | 290 |
NONE => Var (ixn, typ_subst_TVars iTs T) |
291 |
| SOME t => t) |
|
292 |
| subst (b as Bound _) = b |
|
293 |
| subst (Abs (a, T, t)) = Abs(a, typ_subst_TVars iTs T, subst t) |
|
294 |
| subst (f $ t) = subst f $ subst t |
|
295 |
in subst end; |
|
296 |
||
18937 | 297 |
|
298 |
(* expand_atom *) |
|
299 |
||
19422 | 300 |
fun expand_atom T (U, u) = |
301 |
subst_TVars (Type.raw_match (U, T) Vartab.empty) u |
|
18937 | 302 |
handle Type.TYPE_MATCH => raise TYPE ("expand_atom: ill-typed replacement", [T, U], [u]); |
303 |
||
0 | 304 |
end; |