From: Andrea Asperti Date: Wed, 27 Jan 2010 08:47:27 +0000 (+0000) Subject: Added a parameter no_implicit (default true) to choose between raising X-Git-Tag: make_still_working~3091 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=c35e139601a743e7e4b6f4abda745628efdb4744;p=helm.git Added a parameter no_implicit (default true) to choose between raising assert false or returning the identity. --- diff --git a/helm/software/components/ng_kernel/nCicSubstitution.ml b/helm/software/components/ng_kernel/nCicSubstitution.ml index 43a2f8174..d3e6756d8 100644 --- a/helm/software/components/ng_kernel/nCicSubstitution.ml +++ b/helm/software/components/ng_kernel/nCicSubstitution.ml @@ -22,7 +22,7 @@ module Ref = NReference let debug_print = fun _ -> ();; -let lift_from k n = +let lift_from ?(no_implicit=true) k n = let rec liftaux k = function | C.Rel m as t -> if m < k then t else C.Rel (m + n) | C.Meta (i,(m,(C.Irl 0 as l))) when k <= m+1 -> C.Meta (i,(m,l)) @@ -31,15 +31,16 @@ let lift_from k n = | C.Meta (i,(m,l)) -> let lctx = NCicUtils.expand_local_context l in C.Meta (i, (m, C.Ctx (HExtlib.sharing_map (liftaux (k-m)) lctx))) - | C.Implicit _ -> (* was the identity *) assert false + | C.Implicit _ as t -> (* was the identity *) + if no_implicit then assert false + else t | t -> NCicUtils.map (fun _ k -> k + 1) k liftaux t in liftaux k ;; -let lift ?(from=1) n t = - if n = 0 then t - else lift_from from n t +let lift ?(from=1) ?(no_implicit=true) n t = + if n = 0 then t else lift_from ~no_implicit from n t ;; @@ -50,7 +51,7 @@ let lift ?(from=1) n t = (* well typed and avoid_beta_redexes is true. *) (* map_arg is ReductionStrategy.from_env_for_unwind when psubst is *) (* used to implement nCicReduction.unwind' *) -let rec psubst ?(avoid_beta_redexes=false) map_arg args = +let rec psubst ?(avoid_beta_redexes=false) ?(no_implicit=true) map_arg args = let nargs = List.length args in let rec substaux k = function | C.Rel n as t -> @@ -59,7 +60,7 @@ let rec psubst ?(avoid_beta_redexes=false) map_arg args = if nargs <> 0 then C.Rel (n - nargs) else t | n when n < k -> t | n (* k <= n < k+nargs *) -> - (try lift (k-1) (map_arg (List.nth args (n-k))) + (try lift ~no_implicit (k-1) (map_arg (List.nth args (n-k))) with Failure _ | Invalid_argument _ -> assert false)) | C.Meta (i,(m,l)) as t when m >= k + nargs - 1 -> if nargs <> 0 then C.Meta (i,(m-nargs,l)) else t @@ -67,8 +68,11 @@ let rec psubst ?(avoid_beta_redexes=false) map_arg args = | C.Meta (i,(m,l)) -> let lctx = NCicUtils.expand_local_context l in C.Meta (i,(0, - C.Ctx (HExtlib.sharing_map (fun x -> substaux k (lift m x)) lctx))) - | C.Implicit _ -> assert false (* was identity *) + C.Ctx (HExtlib.sharing_map + (fun x -> substaux k (lift ~no_implicit m x)) lctx))) + | C.Implicit _ as t -> + if no_implicit then assert false (* was identity *) + else t | C.Appl (he::tl) as t -> (* Invariant: no Appl applied to another Appl *) let rec avoid he' = function @@ -80,7 +84,8 @@ let rec psubst ?(avoid_beta_redexes=false) map_arg args = (* map_arg is here \x.x, Obj magic is needed because * we don't have polymorphic recursion w/o records *) avoid (psubst - ~avoid_beta_redexes Obj.magic [Obj.magic arg] bo) tl' + ~avoid_beta_redexes ~no_implicit + Obj.magic [Obj.magic arg] bo) tl' | _ -> if he == he' && args == tl then t else C.Appl (he'::args)) in let tl = HExtlib.sharing_map (substaux k) tl in @@ -90,8 +95,8 @@ let rec psubst ?(avoid_beta_redexes=false) map_arg args = substaux 1 ;; -let subst ?avoid_beta_redexes arg = - psubst ?avoid_beta_redexes (fun x -> x)[arg];; +let subst ?avoid_beta_redexes ?no_implicit arg = + psubst ?avoid_beta_redexes ?no_implicit(fun x -> x)[arg];; (* subst_meta (n, C.Ctx [t_1 ; ... ; t_n]) t *) (* returns the term [t] where [Rel i] is substituted with [t_i] lifted by n *) diff --git a/helm/software/components/ng_kernel/nCicSubstitution.mli b/helm/software/components/ng_kernel/nCicSubstitution.mli index 38408fe13..ad8074dc7 100644 --- a/helm/software/components/ng_kernel/nCicSubstitution.mli +++ b/helm/software/components/ng_kernel/nCicSubstitution.mli @@ -22,14 +22,16 @@ val set_ppterm : (context:NCic.context -> (* [from] default 1, lifts only indexes >= [from] *) (* NOTE: the opposite function (delift_rels) is defined in CicMetaSubst *) (* since it needs to restrict the metavariables in case of failure *) -val lift : ?from:int -> int -> NCic.term -> NCic.term +val lift : ?from:int -> ?no_implicit:bool -> int -> NCic.term -> NCic.term (* subst t1 t2 *) (* substitutes [t1] for [Rel 1] in [t2] *) (* if avoid_beta_redexes is true (default: false) no new beta redexes *) (* are generated. WARNING: the substitution can diverge when t2 is not *) (* well typed and avoid_beta_redexes is true. *) -val subst : ?avoid_beta_redexes:bool -> NCic.term -> NCic.term -> NCic.term +val subst : + ?avoid_beta_redexes:bool -> ?no_implicit:bool -> + NCic.term -> NCic.term -> NCic.term (* psubst [avoid] [map_arg] [args] [t] * [avoid] : do not leave newly created beta-redexes, default false @@ -39,7 +41,7 @@ val subst : ?avoid_beta_redexes:bool -> NCic.term -> NCic.term -> NCic.term * the function is ReductionStrategy.from_env_for_unwind when psubst is * used to implement nCicReduction.unwind' *) val psubst : - ?avoid_beta_redexes:bool -> + ?avoid_beta_redexes:bool -> ?no_implicit:bool -> ('a -> NCic.term) -> 'a list -> NCic.term -> NCic.term