X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Fcomponents%2Fng_kernel%2FnCicSubstitution.ml;h=0ca566cc3df4f30d44c53df1c8be3fa03b235eb2;hb=894d518aa760c9f816ddb0dc2b3fa88e1fe20a94;hp=d3e6756d8322bd562149762cb81bf0817a1afd72;hpb=a4a2345e2efaf4cc64aa4daf40e2bce05a400f12;p=helm.git diff --git a/matita/components/ng_kernel/nCicSubstitution.ml b/matita/components/ng_kernel/nCicSubstitution.ml index d3e6756d8..0ca566cc3 100644 --- a/matita/components/ng_kernel/nCicSubstitution.ml +++ b/matita/components/ng_kernel/nCicSubstitution.ml @@ -11,18 +11,12 @@ (* $Id$ *) -let ppterm = - ref (fun ~context:_ ~subst:_ ~metasenv:_ ?inside_fix _ -> - let _ = inside_fix in assert false) -;; -let set_ppterm f = ppterm := f;; - module C = NCic module Ref = NReference let debug_print = fun _ -> ();; -let lift_from ?(no_implicit=true) k n = +let lift_from status ?(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)) @@ -34,13 +28,13 @@ let lift_from ?(no_implicit=true) k n = | 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 + | t -> NCicUtils.map status (fun _ k -> k + 1) k liftaux t in liftaux k ;; -let lift ?(from=1) ?(no_implicit=true) n t = - if n = 0 then t else lift_from ~no_implicit from n t +let lift status ?(from=1) ?(no_implicit=true) n t = + if n = 0 then t else lift_from status ~no_implicit from n t ;; @@ -51,7 +45,7 @@ let lift ?(from=1) ?(no_implicit=true) 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) ?(no_implicit=true) map_arg args = +let rec psubst status ?(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 -> @@ -60,7 +54,7 @@ let rec psubst ?(avoid_beta_redexes=false) ?(no_implicit=true) 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 ~no_implicit (k-1) (map_arg (List.nth args (n-k))) + (try lift status ~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 @@ -69,7 +63,7 @@ let rec psubst ?(avoid_beta_redexes=false) ?(no_implicit=true) map_arg args = let lctx = NCicUtils.expand_local_context l in C.Meta (i,(0, C.Ctx (HExtlib.sharing_map - (fun x -> substaux k (lift ~no_implicit m x)) lctx))) + (fun x -> substaux k (lift status ~no_implicit m x)) lctx))) | C.Implicit _ as t -> if no_implicit then assert false (* was identity *) else t @@ -83,27 +77,27 @@ let rec psubst ?(avoid_beta_redexes=false) ?(no_implicit=true) map_arg args = | C.Lambda (_,_,bo) when avoid_beta_redexes -> (* map_arg is here \x.x, Obj magic is needed because * we don't have polymorphic recursion w/o records *) - avoid (psubst + avoid (psubst status ~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 avoid (substaux k he) tl - | t -> NCicUtils.map (fun _ k -> k + 1) k substaux t + | t -> NCicUtils.map status (fun _ k -> k + 1) k substaux t in substaux 1 ;; -let subst ?avoid_beta_redexes ?no_implicit arg = - psubst ?avoid_beta_redexes ?no_implicit(fun x -> x)[arg];; +let subst status ?avoid_beta_redexes ?no_implicit arg = + psubst status ?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 *) (* [t_i] is lifted as usual when it crosses an abstraction *) -(* subst_meta (n, (C.Irl _ | C.Ctx [])) t | -> lift n t *) -let subst_meta = function +(* subst_meta (n, (C.Irl _ | C.Ctx [])) t | -> lift status n t *) +let subst_meta status = function | m, C.Irl _ - | m, C.Ctx [] -> lift m - | m, C.Ctx l -> psubst (lift m) l + | m, C.Ctx [] -> lift status m + | m, C.Ctx l -> psubst status (lift status m) l ;;