let u = OCic2NCic.nuri_of_ouri u in
indent := 0;
match NCicLibrary.get_obj u with
- | _,_,_,_,NCic.Constant (_,_,_, ty, _) ->
+ | _,_,_,_,NCic.Constant (_,_,Some bo, ty, _) ->
let rec intros = function
| NCic.Prod (name, s, t) ->
let ctx, t = intros t in
| NCic.Appl (NCic.Const (NReference.Ref (u,_))::ty::_)
when NUri.string_of_uri u = "cic:/matita/tests/hole.con" ->
let menv, ty = perforate ctx menv ty in
- let a,b,_ = NCicMetaSubst.mk_meta menv ctx (Some ty) in a,b
+ let a,b,_ = NCicMetaSubst.mk_meta menv ctx (`WithType ty) in a,b
| t ->
NCicUntrusted.map_term_fold_a
(fun e ctx -> e::ctx) ctx perforate menv t
in
+ let rec curryfy ctx = function
+ | NCic.Lambda (name, s, tgt) ->
+ let tgt = curryfy ((name,NCic.Decl s) :: ctx) tgt in
+ NCic.Lambda (name, NCic.Implicit `Type, tgt)
+ | t ->
+ NCicUtils.map
+ (fun e ctx -> e::ctx) ctx curryfy t
+ in
+(*
let ctx, pty = intros ty in
let menv, pty = perforate ctx [] pty in
+*)
(*
let sty, menv, _ =
NCicMetaSubst.saturate ~delta:max_int [] ctx ty 0
in
*)
(* let ctx, ty = intros ty in *)
+(*
let left, right =
match NCicReduction.whd ~delta:max_int ctx pty with
| NCic.Appl [eq;t;a;b] -> a, b
| _-> assert false
in
-
+*)
(*
let whd ty =
(NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx ity)
(NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx sty));
*)
+ let menv, subst, bo, infty =
+ NCicRefiner.typeof [] [] [] (curryfy [] bo) None
+ in
let metasenv, subst =
try
- NCicUnification.unify menv [] ctx left right
+ NCicUnification.unify menv subst [] infty ty
with
| NCicUnification.Uncertain msg
| NCicUnification.UnificationFailure msg
[], []
| Sys.Break -> [],[]
in
- if (NCicReduction.are_convertible ~subst ctx left right)
+ if (NCicReduction.are_convertible ~subst [] infty ty)
then
prerr_endline ("OK: " ^ NUri.string_of_uri u)
else
- (prerr_endline ("FAIL: " ^ NUri.string_of_uri u);
+ (
+ let ctx = [] in
+ let right = infty in
+ let left = ty in
+
+ prerr_endline ("FAIL: " ^ NUri.string_of_uri u);
prerr_endline
(Printf.sprintf
("\t\tRESULT OF UNIF\n\nsubst:\n%s\nmenv:\n%s\n" ^^
let mk_meta ?name metasenv context ty =
match ty with
- | None ->
- let len = List.length context in
+ | `Typeless ->
+ let n = newmeta () in
+ let ty = NCic.Implicit (`Typeof n) in
+ let menv_entry = (n, (name, context, ty)) in
+ menv_entry :: metasenv,NCic.Meta (n, (0,NCic.Irl (List.length context))), ty
+ | `Type
+ | `Term ->
+ let context_for_ty = if ty = `Type then [] else context in
let n = newmeta () in
- let ty_menv_entry = (n, (name, context, NCic.Implicit (`Typeof n))) in
+ let ty_menv_entry = (n, (name,context_for_ty, NCic.Implicit (`Typeof n))) in
let m = newmeta () in
- let ty = NCic.Meta (n, (0,NCic.Irl len)) in
+ let ty = NCic.Meta (n, (0,NCic.Irl (List.length context_for_ty))) in
let menv_entry = (m, (name, context, ty)) in
- menv_entry :: ty_menv_entry :: metasenv, NCic.Meta (m, (0,NCic.Irl len)), ty
- | Some ty ->
+ menv_entry :: ty_menv_entry :: metasenv,
+ NCic.Meta (m, (0,NCic.Irl (List.length context))), ty
+ | `WithType ty ->
let n = newmeta () in
let len = List.length context in
let menv_entry = (n, (name, context, ty)) in
assert (goal_arity >= 0);
let rec aux metasenv = function
| NCic.Prod (name,s,t) ->
- let metasenv1, arg,_ = mk_meta ~name:name metasenv context (Some s) in
+ let metasenv1, arg,_ =
+ mk_meta ~name:name metasenv context (`WithType s) in
let t, metasenv1, args, pno =
aux metasenv1 (NCicSubstitution.subst arg t)
in
;;
let exp_implicit metasenv context expty =
+ let foo x = match expty with Some t -> `WithType t | None -> x in
function
- | `Closed -> NCicMetaSubst.mk_meta metasenv [] expty
- | `Type | `Term -> NCicMetaSubst.mk_meta metasenv context expty
+ | `Closed -> NCicMetaSubst.mk_meta metasenv [] (foo `Type)
+ | `Type -> NCicMetaSubst.mk_meta metasenv context (foo `Type)
+ | `Term -> NCicMetaSubst.mk_meta metasenv context (foo `Term)
+ | _ -> assert false
+;;
+
+let force_to_sort metasenv subst context t =
+ match NCicReduction.whd ~subst context t with
+ | C.Meta (_,(_,(C.Irl 0 | C.Ctx []))) as t ->
+ metasenv, subst, t
+ | C.Meta (i,(_,lc)) as t ->
+ let len = match lc with C.Irl len->len | C.Ctx l->List.length l in
+ prerr_endline "RESTRICT";
+ let metasenv, subst, _ =
+ NCicMetaSubst.restrict metasenv subst i (HExtlib.list_seq 1 len)
+ in
+ metasenv, subst, t
+ | C.Sort _ -> metasenv, subst, t
| _ -> assert false
;;
let sort_of_prod
localise metasenv subst context orig_s orig_t (name,s) t (t1, t2)
=
- let restrict metasenv subst = function
- | C.Meta (_,(_,(C.Irl 0 | C.Ctx []))) as t ->
- metasenv, subst, t
- | C.Meta (i,(_,lc)) as t ->
- let len = match lc with C.Irl len->len | C.Ctx l->List.length l in
- let metasenv, subst, _ =
- NCicMetaSubst.restrict metasenv subst i (HExtlib.list_seq 1 len)
- in
- metasenv, subst, t
- | t -> metasenv, subst, t
- in
- let t1 = NCicReduction.whd ~subst context t1 in
- let t2 = NCicReduction.whd ~subst ((name,C.Decl s)::context) t2 in
- let metasenv, subst, t1 = restrict metasenv subst t1 in
- let metasenv, subst, t2 = restrict metasenv subst t2 in
+ let metasenv, subst, t1 = force_to_sort metasenv subst context t1 in
+ let metasenv, subst, t2 =
+ force_to_sort metasenv subst ((name,C.Decl s)::context) t2 in
+ prerr_endline ("S1:"^NCicPp.ppterm ~metasenv ~subst ~context t1);
+ prerr_endline ("S2:"^NCicPp.ppterm ~metasenv ~subst ~context:((name,C.Decl s)::context) t2);
match t1, t2 with
| C.Sort _, C.Sort C.Prop -> metasenv, subst, t2
| C.Sort (C.Type u1), C.Sort (C.Type u2) ->
match arity1 with
| C.Prod (name,so1,de1) (* , t ==?== C.Prod _ *) ->
let metasenv, meta, _ =
- NCicMetaSubst.mk_meta metasenv ((name,C.Decl so1)::context) None
+ NCicMetaSubst.mk_meta metasenv ((name,C.Decl so1)::context) `Typeless
in
let metasenv, subst =
try NCicUnification.unify metasenv subst context
aux metasenv subst ((name, C.Decl so1)::context)
(mkapp (NCicSubstitution.lift 1 ind) (C.Rel 1)) de1 meta
| C.Sort _ (* , t ==?== C.Prod _ *) ->
- let metasenv, meta, _ =
- NCicMetaSubst.mk_meta metasenv (("_",C.Decl ind)::context) None
- in
+ let metasenv, meta, _ = NCicMetaSubst.mk_meta metasenv [] `Typeless in
+ prerr_endline (
+ (NCicPp.ppterm ~subst ~metasenv ~context (C.Prod ("_", ind, meta))) ^ " ==== " ^
+ (NCicPp.ppterm ~subst ~metasenv ~context arity2) ^ "\nMENV:\n"
+ ^ NCicPp.ppmetasenv ~subst metasenv);
let metasenv, subst =
try NCicUnification.unify metasenv subst context
(C.Prod ("_", ind, meta)) arity2
(NCicPp.ppterm ~subst ~metasenv ~context arity2))) exc)
in
(try NCicTypeChecker.check_allowed_sort_elimination
- ~metasenv ~subst r context ind arity1 arity2
+ ~metasenv ~subst r context ind arity1 arity2;
+ metasenv, subst
with exc -> raise (wrap_exc (lazy (localise orig,
"Sort elimination not allowed ")) exc))
| _ -> assert false
| C.Implicit _
| C.Lambda _ -> metasenv, subst, t, expty
| _ ->
+ prerr_endline ("F:" ^
+ (NCicPp.ppterm ~metasenv ~subst ~context infty) ^ " === " ^
+ (NCicPp.ppterm ~metasenv ~subst ~context expty) ^ "\nMENV:\n" ^
+ NCicPp.ppmetasenv ~subst metasenv);
let metasenv, subst =
try NCicUnification.unify metasenv subst context infty expty
with exc -> raise (wrap_exc (lazy (localise orig, Printf.sprintf
| None -> metasenv, subst, t, infty
in
let rec typeof_aux metasenv subst context expty =
- fun t as orig -> (*prerr_endline (NCicPp.ppterm ~metasenv ~subst ~context t);*)
+ fun t as orig ->
+ prerr_endline ("R:"^NCicPp.ppterm ~metasenv ~subst ~context t);
let metasenv, subst, t, infty =
match t with
| C.Rel n ->
| C.Prod (_,s,t) -> Some s, Some t
| _ -> None, None
in
- let metasenv, subst, s, _ = typeof_aux metasenv subst context None s in
+ let metasenv, subst, s, ty_s =
+ typeof_aux metasenv subst context None s in
+ let metasenv, subst, _ = force_to_sort metasenv subst context ty_s in
let (metasenv,subst), exp_ty_t =
match exp_s with
| Some exp_s ->
in
metasenv, subst, C.Lambda(n,s,t), C.Prod (n,s,ty_t)
| C.LetIn (n,ty,t,bo) ->
- let metasenv, subst, ty, _ = typeof_aux metasenv subst context None ty in
+ let metasenv, subst, ty, ty_ty =
+ typeof_aux metasenv subst context None ty in
+ let metasenv, subst, _ = force_to_sort metasenv subst context ty_ty in
let metasenv, subst, t, _ =
typeof_aux metasenv subst context (Some ty) t in
let context = (n, C.Def (t,ty)) :: context in
else C.Appl ((C.Const r)::parameters) in
let metasenv, subst, ind, ind_ty =
typeof_aux metasenv subst context None ind in
- check_allowed_sort_elimination localise r orig_term metasenv subst context
- ind ind_ty outsort;
+ let metasenv, subst =
+ check_allowed_sort_elimination localise r orig_term metasenv subst
+ context ind ind_ty outsort
+ in
(* let's check if the type of branches are right *)
if List.length pl <> constructorsno then
raise (RefineFailure (lazy (localise orig,
typeof ~localise metasenv subst context arg None in
let metasenv, meta, _ =
NCicMetaSubst.mk_meta metasenv
- (("_",C.Decl ty_arg) :: context) None
+ (("_",C.Decl ty_arg) :: context) `Type
in
let flex_prod = C.Prod ("_", ty_arg, meta) in
+ prerr_endline ("F:" ^
+ (NCicPp.ppterm ~metasenv ~subst ~context t) ^ " === " ^
+ (NCicPp.ppterm ~metasenv ~subst ~context flex_prod) ^ "\nMENV:\n" ^
+ NCicPp.ppmetasenv ~subst metasenv ^ "\nCTX:\n" ^
+ NCicPp.ppcontext ~metasenv ~subst context);
let metasenv, subst =
try NCicUnification.unify metasenv subst context t flex_prod
with exc -> raise (wrap_exc (lazy (localise orig_he, Printf.sprintf