227 |
227 |
228 (*Perform eta-contractions upon a term*) |
228 (*Perform eta-contractions upon a term*) |
229 fun eta_contract (Abs(a,T,body)) = |
229 fun eta_contract (Abs(a,T,body)) = |
230 (case eta_contract body of |
230 (case eta_contract body of |
231 body' as (f $ Bound i) => |
231 body' as (f $ Bound i) => |
232 if i=0 andalso not (0 mem loose_bnos f) then incr_boundvars ~1 f |
232 if i=0 andalso not (0 mem loose_bnos f) then incr_boundvars ~1 f |
233 else Abs(a,T,body') |
233 else Abs(a,T,body') |
234 | body' => Abs(a,T,body')) |
234 | body' => Abs(a,T,body')) |
235 | eta_contract(f$t) = eta_contract f $ eta_contract t |
235 | eta_contract(f$t) = eta_contract f $ eta_contract t |
236 | eta_contract t = t; |
236 | eta_contract t = t; |
237 |
237 |
238 |
238 |
245 Instantiation does not affect the object, so matching ?a with ?a+1 works. |
245 Instantiation does not affect the object, so matching ?a with ?a+1 works. |
246 A Const does not match a Free of the same name! |
246 A Const does not match a Free of the same name! |
247 Does not notice eta-equality, thus f does not match %(x)f(x) *) |
247 Does not notice eta-equality, thus f does not match %(x)f(x) *) |
248 fun fomatch tsig (pat,obj) = |
248 fun fomatch tsig (pat,obj) = |
249 let fun typ_match args = (Type.typ_match tsig args) |
249 let fun typ_match args = (Type.typ_match tsig args) |
250 handle Type.TYPE_MATCH => raise MATCH; |
250 handle Type.TYPE_MATCH => raise MATCH; |
251 fun mtch (tyinsts,insts) = fn |
251 fun mtch (tyinsts,insts) = fn |
252 (Var(ixn,T), t) => |
252 (Var(ixn,T), t) => |
253 if loose_bvar(t,0) then raise MATCH |
253 if loose_bvar(t,0) then raise MATCH |
254 else (case assoc(insts,ixn) of |
254 else (case assoc(insts,ixn) of |
255 None => (typ_match (tyinsts, (T, fastype_of t)), |
255 None => (typ_match (tyinsts, (T, fastype_of t)), |
256 (ixn,t)::insts) |
256 (ixn,t)::insts) |
257 | Some u => if t aconv u then (tyinsts,insts) else raise MATCH) |
257 | Some u => if t aconv u then (tyinsts,insts) else raise MATCH) |
258 | (Free (a,T), Free (b,U)) => |
258 | (Free (a,T), Free (b,U)) => |
259 if a=b then (typ_match (tyinsts,(T,U)), insts) else raise MATCH |
259 if a=b then (typ_match (tyinsts,(T,U)), insts) else raise MATCH |
260 | (Const (a,T), Const (b,U)) => |
260 | (Const (a,T), Const (b,U)) => |
261 if a=b then (typ_match (tyinsts,(T,U)), insts) else raise MATCH |
261 if a=b then (typ_match (tyinsts,(T,U)), insts) else raise MATCH |
262 | (Bound i, Bound j) => |
262 | (Bound i, Bound j) => |
263 if i=j then (tyinsts,insts) else raise MATCH |
263 if i=j then (tyinsts,insts) else raise MATCH |
264 | (Abs(_,T,t), Abs(_,U,u)) => |
264 | (Abs(_,T,t), Abs(_,U,u)) => |
265 mtch (typ_match (tyinsts,(T,U)),insts) (t,u) |
265 mtch (typ_match (tyinsts,(T,U)),insts) (t,u) |
266 | (f$t, g$u) => mtch (mtch (tyinsts,insts) (f,g)) (t, u) |
266 | (f$t, g$u) => mtch (mtch (tyinsts,insts) (f,g)) (t, u) |
267 | _ => raise MATCH |
267 | _ => raise MATCH |
268 in mtch([],[]) (eta_contract pat,eta_contract obj) end; |
268 in mtch([],[]) (eta_contract pat,eta_contract obj) end; |
269 |
269 |
270 |
270 |