355 fun mtch (instsp as (tyinsts,insts)) = fn |
355 fun mtch (instsp as (tyinsts,insts)) = fn |
356 (Var(ixn,T), t) => |
356 (Var(ixn,T), t) => |
357 if loose_bvar(t,0) then raise MATCH |
357 if loose_bvar(t,0) then raise MATCH |
358 else (case Envir.lookup' (insts, (ixn, T)) of |
358 else (case Envir.lookup' (insts, (ixn, T)) of |
359 NONE => (typ_match thy (tyinsts, (T, fastype_of t)), |
359 NONE => (typ_match thy (tyinsts, (T, fastype_of t)), |
360 Vartab.curried_update_new (ixn, (T, t)) insts) |
360 Vartab.update_new (ixn, (T, t)) insts) |
361 | SOME u => if t aeconv u then instsp else raise MATCH) |
361 | SOME u => if t aeconv u then instsp else raise MATCH) |
362 | (Free (a,T), Free (b,U)) => |
362 | (Free (a,T), Free (b,U)) => |
363 if a=b then (typ_match thy (tyinsts,(T,U)), insts) else raise MATCH |
363 if a=b then (typ_match thy (tyinsts,(T,U)), insts) else raise MATCH |
364 | (Const (a,T), Const (b,U)) => |
364 | (Const (a,T), Const (b,U)) => |
365 if a=b then (typ_match thy (tyinsts,(T,U)), insts) else raise MATCH |
365 if a=b then (typ_match thy (tyinsts,(T,U)), insts) else raise MATCH |
376 (* Matching of higher-order patterns *) |
376 (* Matching of higher-order patterns *) |
377 |
377 |
378 fun match_bind(itms,binders,ixn,T,is,t) = |
378 fun match_bind(itms,binders,ixn,T,is,t) = |
379 let val js = loose_bnos t |
379 let val js = loose_bnos t |
380 in if null is |
380 in if null is |
381 then if null js then Vartab.curried_update_new (ixn, (T, t)) itms else raise MATCH |
381 then if null js then Vartab.update_new (ixn, (T, t)) itms else raise MATCH |
382 else if js subset_int is |
382 else if js subset_int is |
383 then let val t' = if downto0(is,length binders - 1) then t |
383 then let val t' = if downto0(is,length binders - 1) then t |
384 else mapbnd (idx is) t |
384 else mapbnd (idx is) t |
385 in Vartab.curried_update_new (ixn, (T, mkabs (binders, is, t'))) itms end |
385 in Vartab.update_new (ixn, (T, mkabs (binders, is, t'))) itms end |
386 else raise MATCH |
386 else raise MATCH |
387 end; |
387 end; |
388 |
388 |
389 fun match thy (po as (pat,obj)) = |
389 fun match thy (po as (pat,obj)) = |
390 let |
390 let |