379 *} |
379 *} |
380 |
380 |
381 ML {* |
381 ML {* |
382 (* - applies f to the subterm of an abstraction, *) |
382 (* - applies f to the subterm of an abstraction, *) |
383 (* otherwise to the given term, *) |
383 (* otherwise to the given term, *) |
384 (* - used by REGULARIZE, therefore abstracted *) |
384 (* - used by regularize, therefore abstracted *) |
385 (* variables do not have to be treated specially *) |
385 (* variables do not have to be treated specially *) |
386 |
386 |
387 fun apply_subt f trm1 trm2 = |
387 fun apply_subt f trm1 trm2 = |
388 case (trm1, trm2) of |
388 case (trm1, trm2) of |
389 (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t') |
389 (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t') |
397 (* produces a regularized version of rtm *) |
397 (* produces a regularized version of rtm *) |
398 (* - the result is still not completely typed *) |
398 (* - the result is still not completely typed *) |
399 (* - does not need any special treatment of *) |
399 (* - does not need any special treatment of *) |
400 (* bound variables *) |
400 (* bound variables *) |
401 |
401 |
402 fun REGULARIZE_trm lthy rtrm qtrm = |
402 fun regularize_trm lthy rtrm qtrm = |
403 case (rtrm, qtrm) of |
403 case (rtrm, qtrm) of |
404 (Abs (x, ty, t), Abs (x', ty', t')) => |
404 (Abs (x, ty, t), Abs (x', ty', t')) => |
405 let |
405 let |
406 val subtrm = REGULARIZE_trm lthy t t' |
406 val subtrm = regularize_trm lthy t t' |
407 in |
407 in |
408 if ty = ty' |
408 if ty = ty' |
409 then Abs (x, ty, subtrm) |
409 then Abs (x, ty, subtrm) |
410 else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm |
410 else mk_babs $ (mk_resp $ mk_resp_arg lthy (ty, ty')) $ subtrm |
411 end |
411 end |
412 | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
412 | (Const (@{const_name "All"}, ty) $ t, Const (@{const_name "All"}, ty') $ t') => |
413 let |
413 let |
414 val subtrm = apply_subt (REGULARIZE_trm lthy) t t' |
414 val subtrm = apply_subt (regularize_trm lthy) t t' |
415 in |
415 in |
416 if ty = ty' |
416 if ty = ty' |
417 then Const (@{const_name "All"}, ty) $ subtrm |
417 then Const (@{const_name "All"}, ty) $ subtrm |
418 else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
418 else mk_ball $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
419 end |
419 end |
420 | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
420 | (Const (@{const_name "Ex"}, ty) $ t, Const (@{const_name "Ex"}, ty') $ t') => |
421 let |
421 let |
422 val subtrm = apply_subt (REGULARIZE_trm lthy) t t' |
422 val subtrm = apply_subt (regularize_trm lthy) t t' |
423 in |
423 in |
424 if ty = ty' |
424 if ty = ty' |
425 then Const (@{const_name "Ex"}, ty) $ subtrm |
425 then Const (@{const_name "Ex"}, ty) $ subtrm |
426 else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
426 else mk_bex $ (mk_resp $ mk_resp_arg lthy (qnt_typ ty, qnt_typ ty')) $ subtrm |
427 end |
427 end |
428 (* FIXME: Should = only be replaced, when fully applied? *) |
428 (* FIXME: Should = only be replaced, when fully applied? *) |
429 (* Then there must be a 2nd argument *) |
429 (* Then there must be a 2nd argument *) |
430 | (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') => |
430 | (Const (@{const_name "op ="}, ty) $ t, Const (@{const_name "op ="}, ty') $ t') => |
431 let |
431 let |
432 val subtrm = REGULARIZE_trm lthy t t' |
432 val subtrm = regularize_trm lthy t t' |
433 in |
433 in |
434 if ty = ty' |
434 if ty = ty' |
435 then Const (@{const_name "op ="}, ty) $ subtrm |
435 then Const (@{const_name "op ="}, ty) $ subtrm |
436 else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm |
436 else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm |
437 end |
437 end |
438 | (t1 $ t2, t1' $ t2') => |
438 | (t1 $ t2, t1' $ t2') => |
439 (REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2') |
439 (regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2') |
440 | (Free (x, ty), Free (x', ty')) => |
440 | (Free (x, ty), Free (x', ty')) => |
441 if x = x' |
441 if x = x' |
442 then rtrm (* FIXME: check whether types corresponds *) |
442 then rtrm (* FIXME: check whether types corresponds *) |
443 else raise (LIFT_MATCH "regularize (frees)") |
443 else raise (LIFT_MATCH "regularize (frees)") |
444 | (Bound i, Bound i') => |
444 | (Bound i, Bound i') => |