exception Uncertain of string Lazy.t;;
exception AssertFailure of string Lazy.t;;
+let refiner_typeof =
+ ref (fun _ ?localise _ _ _ _ _ -> ignore localise; assert false);;
+let set_refiner_typeof f = refiner_typeof := f
+;;
+
let (===) x y = Pervasives.compare x y = 0 ;;
let uncert_exc metasenv subst context t1 t2 =
let indent = ref "";;
let inside c = indent := !indent ^ String.make 1 c;;
-let outside () = indent := String.sub !indent 0 (String.length !indent -1);;
+let outside () =
+ try
+ indent := String.sub !indent 0 (String.length !indent -1)
+ with
+ Invalid_argument _ -> indent := "??"; ()
+;;
let pp s =
prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ Lazy.force s)
let ppcontext = NCicPp.ppcontext;;
let ppmetasenv = NCicPp.ppmetasenv;;
-(*let ppcontext ~metasenv ~subst context = "...";;
-let ppmetasenv ~subst metasenv = "...";;*)
+let ppcontext ~metasenv:_metasenv ~subst:_subst _context = "...";;
+let ppmetasenv ~subst:_subst _metasenv = "...";;
let pp _ = ();;
with NCicUtils.Subst_not_found _ -> false
;;
+let rec mk_irl =
+ function
+ 0 -> []
+ | n -> NCic.Rel n :: mk_irl (n-1)
+;;
-let rec lambda_intros metasenv subst context t args =
+let rec lambda_intros rdb metasenv subst context t args =
let tty = NCicTypeChecker.typeof ~metasenv ~subst context t in
- let argsty = List.map (NCicTypeChecker.typeof ~metasenv ~subst context) args in
- let rec mk_lambda context n = function
- | [] ->
+ let argsty =
+ List.map
+ (fun arg -> arg, NCicTypeChecker.typeof ~metasenv ~subst context arg) args in
+ let context_of_args = context in
+ let mk_appl = function [] -> assert false | [t] -> t | l -> NCic.Appl l in
+ let rec mk_lambda metasenv subst context n processed_args = function
+ | [] ->
let metasenv, _, bo, _ =
NCicMetaSubst.mk_meta metasenv context
(`WithType (NCicSubstitution.lift n tty))
in
- metasenv, bo
- | ty::tail ->
+ metasenv, subst, bo
+ | (arg,ty)::tail ->
let name = "HBeta"^string_of_int n in
- let ty = NCicSubstitution.lift n ty in
- let metasenv, bo = mk_lambda ((name,NCic.Decl ty)::context) (n+1) tail in
- metasenv, NCic.Lambda (name, ty, bo)
+ let metasenv,_,instance,_ =
+ NCicMetaSubst.mk_meta metasenv context_of_args `Term in
+ let meta_applied = mk_appl (instance::List.rev processed_args) in
+let metasenv,subst,_,_ =
+ !refiner_typeof ((rdb :> NRstatus.status)#set_coerc_db NCicCoercion.empty_db) metasenv subst context_of_args meta_applied None
+in
+prerr_endline ("########################## LI1: " ^ NCicPp.ppterm ~metasenv ~subst ~context:context_of_args meta_applied ^ " vs " ^ NCicPp.ppterm ~metasenv ~subst ~context:context_of_args ty);
+prerr_endline (NCicPp.ppcontext ~metasenv ~subst context_of_args);
+prerr_endline (NCicPp.ppmetasenv metasenv ~subst);
+ let metasenv,subst =
+ unify rdb true metasenv subst context_of_args meta_applied ty in
+prerr_endline "UNIFY FINITA";
+ let telescopic_ty = NCicSubstitution.lift n instance in
+ let telescopic_ty =
+ mk_appl (telescopic_ty :: mk_irl (List.length processed_args)) in
+prerr_endline ("########################## LI: " ^ NCicPp.ppterm ~metasenv ~subst ~context telescopic_ty);
+ let metasenv, subst, bo =
+ mk_lambda metasenv subst ((name,NCic.Decl telescopic_ty)::context) (n+1)
+ (arg::processed_args) tail
+ in
+ metasenv, subst, NCic.Lambda (name, telescopic_ty, bo)
in
- mk_lambda context 0 argsty
+ mk_lambda metasenv subst context 0 [] argsty
and instantiate rdb test_eq_only metasenv subst context n lc t swap =
(*D*) inside 'I'; try let rc =
| NCic.Appl (NCic.Meta (i,l)::args) when
not (NCicMetaSubst.flexible subst args)
->
- let metasenv, lambda_Mj =
- lambda_intros metasenv subst context t1 args
+ let metasenv, subst, lambda_Mj =
+ lambda_intros rdb metasenv subst context t1 args
in
+prerr_endline ("XXXXXXXXX " ^ NCicPp.ppterm ~metasenv ~subst ~context lambda_Mj);
unify rdb test_eq_only metasenv subst context
(C.Meta (i,l)) lambda_Mj,
i
not (NCicMetaSubst.flexible subst args) ->
(* we verify that none of the args is a Meta,
since beta expanding w.r.t a metavariable makes no sense *)
- let metasenv, lambda_Mj =
- lambda_intros metasenv subst context t1 args
+ let metasenv, subst, lambda_Mj =
+ lambda_intros rdb metasenv subst context t1 args
in
let metasenv, subst =
unify rdb test_eq_only metasenv subst context
| _, NCic.Appl (NCic.Meta (i,l)::args) when
not(NCicMetaSubst.flexible subst args) ->
- let metasenv, lambda_Mj =
- lambda_intros metasenv subst context t2 args
+ let metasenv, subst, lambda_Mj =
+ lambda_intros rdb metasenv subst context t2 args
in
let metasenv, subst =
unify rdb test_eq_only metasenv subst context