X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Focaml%2Fcic_omdoc%2Feta_fixing.ml;h=29d22ccb91062051858e1c55f4619b4433e35e35;hb=a864255e782859e2b3b7da08297f5d3fe2ee710d;hp=24242b42675f34f4f4cdefaca68cdaa1a2f4a5d4;hpb=e626927b4c1c77bdcd6b545203a0a9c17a9ff136;p=helm.git diff --git a/helm/ocaml/cic_omdoc/eta_fixing.ml b/helm/ocaml/cic_omdoc/eta_fixing.ml index 24242b426..29d22ccb9 100644 --- a/helm/ocaml/cic_omdoc/eta_fixing.ml +++ b/helm/ocaml/cic_omdoc/eta_fixing.ml @@ -23,9 +23,7 @@ * http://cs.unibo.it/helm/. *) -exception ReferenceToVariable;; -exception RferenceToCurrentProof;; -exception ReferenceToInductiveDefinition;; +exception ReferenceToNonVariable;; let prerr_endline _ = ();; @@ -132,7 +130,11 @@ let fix_according_to_type ty hd tl = let rec aux n ty tl res = if n = 0 then (match tl with - [] -> C.Appl res + [] -> + (match res with + [] -> assert false + | [res] -> res + | _ -> C.Appl res) | _ -> match res with [] -> assert false @@ -163,7 +165,7 @@ let fix_according_to_type ty hd tl = aux expected_arity ty tl [hd] ;; -let eta_fix metasenv t = +let eta_fix metasenv context t = let rec eta_fix' context t = (* prerr_endline ("entering aux with: term=" ^ CicPp.ppterm t); flush stderr ; *) @@ -172,16 +174,11 @@ let eta_fix metasenv t = match t with C.Rel n -> C.Rel n | C.Var (uri,exp_named_subst) -> - let exp_named_subst' = - List.map - (function i,t -> i, (eta_fix' context t)) exp_named_subst - in - C.Var (uri,exp_named_subst') + let exp_named_subst' = fix_exp_named_subst context exp_named_subst in + C.Var (uri,exp_named_subst') | C.Meta (n,l) -> - let (_,canonical_context,_) = - List.find (function (m,_,_) -> n = m) metasenv - in - let l' = + let (_,canonical_context,_) = CicUtil.lookup_meta n metasenv in + let l' = List.map2 (fun ct t -> match (ct, t) with @@ -207,40 +204,30 @@ let eta_fix metasenv t = let l' = List.map (eta_fix' context) l in (match l' with + [] -> assert false + | he::tl -> + let ty = CicTypeChecker.type_of_aux' metasenv context he in + fix_according_to_type ty he tl +(* C.Const(uri,exp_named_subst)::l'' -> let constant_type = (match CicEnvironment.get_obj uri with C.Constant (_,_,ty,_) -> ty | C.Variable _ -> raise ReferenceToVariable - | C.CurrentProof (_,_,_,_,params) -> raise RferenceToCurrentProof + | C.CurrentProof (_,_,_,_,params) -> raise ReferenceToCurrentProof | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition ) in fix_according_to_type constant_type (C.Const(uri,exp_named_subst)) l'' -(* - let result = fix_according_to_type constant_type (C.Const(uri,exp_named_subst)) l'' in - if not (CicReduction.are_convertible [] appl result) then - (prerr_endline ("prima :" ^(CicPp.ppterm appl)); - prerr_endline ("dopo :" ^(CicPp.ppterm result))); - result *) - | _ -> C.Appl l' ) + | _ -> C.Appl l' *)) | C.Const (uri,exp_named_subst) -> - let exp_named_subst' = - List.map - (function i,t -> i, (eta_fix' context t)) exp_named_subst - in - C.Const (uri,exp_named_subst') + let exp_named_subst' = fix_exp_named_subst context exp_named_subst in + C.Const (uri,exp_named_subst') | C.MutInd (uri,tyno,exp_named_subst) -> - let exp_named_subst' = - List.map - (function i,t -> i, (eta_fix' context t)) exp_named_subst - in + let exp_named_subst' = fix_exp_named_subst context exp_named_subst in C.MutInd (uri, tyno, exp_named_subst') | C.MutConstruct (uri,tyno,consno,exp_named_subst) -> - let exp_named_subst' = - List.map - (function i,t -> i, (eta_fix' context t)) exp_named_subst - in + let exp_named_subst' = fix_exp_named_subst context exp_named_subst in C.MutConstruct (uri, tyno, consno, exp_named_subst') | C.MutCase (uri, tyno, outty, term, patterns) as prima -> let outty' = eta_fix' context outty in @@ -299,17 +286,18 @@ let eta_fix metasenv t = List.map (fun (name, ty, bo) -> (name, eta_fix' context ty, eta_fix' (fun_types@context) bo)) funs) - in - eta_fix' [] t + and fix_exp_named_subst context exp_named_subst = + List.rev + (List.fold_left + (fun newsubst (uri,t) -> + let t' = eta_fix' context t in + let ty = + match CicEnvironment.get_obj uri with + Cic.Variable (_,_,ty,_) -> CicSubstitution.subst_vars newsubst ty + | _ -> raise ReferenceToNonVariable in + let t'' = fix_according_to_type ty t' [] in + (uri,t'')::newsubst + ) [] exp_named_subst) + in + eta_fix' context t ;; - - - - - - - - - - -