exception WrongUriToMutualInductiveDefinitions of string;;
exception RelToHiddenHypothesis;;
exception MetasenvInconsistency;;
-exception MutCaseFixAndCofixRefineNotImplemented;;
-exception FreeMetaFound of int;;
exception WrongArgumentNumber;;
let fdebug = ref 0;;
let module C = Cic in
let module R = CicMetaSubst in
let module Un = CicUnification in
- match R.whd subst context expectedtype with
+ match R.whd metasenv subst context expectedtype with
C.MutInd (_,_,_) ->
(n,context,actualtype, [term]), subst, metasenv
| C.Appl (C.MutInd (_,_,_)::tl) ->
| C.Prod (name,so,de) ->
(* we expect that the actual type of the branch has the due
number of Prod *)
- (match R.whd subst context actualtype with
+ (match R.whd metasenv subst context actualtype with
C.Prod (name',so',de') ->
let subst, metasenv =
Un.fo_unif_subst subst context metasenv so so' in
decr fdebug ;
ty,subst',metasenv'
| C.Meta (n,l) ->
- let (_,canonical_context,ty) =
- try
- List.find (function (m,_,_) -> n = m) metasenv
- with
- Not_found -> raise (FreeMetaFound n)
- in
+ let (_,canonical_context,ty) = CicUtil.lookup_meta n metasenv in
let subst',metasenv' =
check_metasenv_consistency subst metasenv context canonical_context l
in
let _,subst',metasenv' =
type_of_aux subst metasenv context ty in
let inferredty,subst'',metasenv'' =
- type_of_aux subst' metasenv' context ty
+ type_of_aux subst' metasenv' context te
in
(try
let subst''',metasenv''' =
raise
(WrongUriToMutualInductiveDefinitions (U.string_of_uri uri)) in
let rec count_prod t =
- match CicMetaSubst.whd subst context t with
+ match CicMetaSubst.whd metasenv subst context t with
C.Prod (_, _, t) -> 1 + (count_prod t)
| _ -> 0 in
let no_args = count_prod arity in
let _, subst, metasenv =
type_of_aux subst metasenv context expected_type
in
- let actual_type = CicMetaSubst.whd subst context actual_type in
+ let actual_type = CicMetaSubst.whd metasenv subst context actual_type in
let subst,metasenv =
Un.fo_unif_subst subst context metasenv expected_type actual_type
in
type_of_aux subst metasenv context appl
in
*)
- CicMetaSubst.whd subst context appl
+ CicMetaSubst.whd metasenv subst context appl
in
Un.fo_unif_subst subst context metasenv instance instance')
(subst,metasenv) outtypeinstances in
- CicMetaSubst.whd subst
+ CicMetaSubst.whd metasenv subst
context (C.Appl(outtype::right_args@[term])),subst,metasenv
- | C.Fix _
- | C.CoFix _ -> raise MutCaseFixAndCofixRefineNotImplemented
+ | C.Fix (i,fl) ->
+ let subst,metasenv,types =
+ List.fold_left
+ (fun (subst,metasenv,types) (n,_,ty,_) ->
+ let _,subst',metasenv' = type_of_aux subst metasenv context ty in
+ subst',metasenv', Some (C.Name n,(C.Decl ty)) :: types
+ ) (subst,metasenv,[]) fl
+ in
+ let len = List.length types in
+ let context' = types@context in
+ let subst,metasenv =
+ List.fold_left
+ (fun (subst,metasenv) (name,x,ty,bo) ->
+ let ty_of_bo,subst,metasenv =
+ type_of_aux subst metasenv context' bo
+ in
+ Un.fo_unif_subst subst context' metasenv
+ ty_of_bo (CicMetaSubst.lift metasenv subst len ty)
+ ) (subst,metasenv) fl in
+
+ let (_,_,ty,_) = List.nth fl i in
+ ty,subst,metasenv
+ | C.CoFix (i,fl) ->
+ let subst,metasenv,types =
+ List.fold_left
+ (fun (subst,metasenv,types) (n,ty,_) ->
+ let _,subst',metasenv' = type_of_aux subst metasenv context ty in
+ subst',metasenv', Some (C.Name n,(C.Decl ty)) :: types
+ ) (subst,metasenv,[]) fl
+ in
+ let len = List.length types in
+ let context' = types@context in
+ let subst,metasenv =
+ List.fold_left
+ (fun (subst,metasenv) (name,ty,bo) ->
+ let ty_of_bo,subst,metasenv =
+ type_of_aux subst metasenv context' bo
+ in
+ Un.fo_unif_subst subst context' metasenv
+ ty_of_bo (CicMetaSubst.lift metasenv subst len ty)
+ ) (subst,metasenv) fl in
+
+ let (_,ty,_) = List.nth fl i in
+ ty,subst,metasenv
(* check_metasenv_consistency checks that the "canonical" context of a
metavariable is consitent - up to relocation via the relocation list l -
let subst',metasenv' = CicMetaSubst.unwind_subst metasenv subst in
let t1' = CicMetaSubst.apply_subst subst' t1 in
let t2' = CicMetaSubst.apply_subst subst' t2 in
- let t1'' = CicMetaSubst.whd subst' context t1' in
- let t2'' = CicMetaSubst.whd subst' ((Some (name,C.Decl s))::context) t2' in
+ let t1'' = CicMetaSubst.whd metasenv subst' context t1' in
+ let t2'' =
+ CicMetaSubst.whd metasenv subst' ((Some (name,C.Decl s))::context) t2'
+ in
match (t1'', t2'') with
(C.Sort s1, C.Sort s2)
when (s2 = C.Prop or s2 = C.Set or s2 = C.CProp) -> (* different from Coq manual!!! *)
function
[] -> hetype,subst,metasenv
| (hete, hety)::tl ->
- (match (CicMetaSubst.whd subst context hetype) with
+ (match (CicMetaSubst.whd metasenv subst context hetype) with
Cic.Prod (n,s,t) ->
let subst',metasenv' =
CicUnification.fo_unif_subst subst context metasenv s hety