aboutsummaryrefslogtreecommitdiff
path: root/kernel/constr.ml
diff options
context:
space:
mode:
authorMaxime Dénès2018-10-26 11:07:19 +0200
committerMaxime Dénès2018-10-26 11:07:19 +0200
commit4ca847d9a656a861bd11e042044a7544c420dde8 (patch)
tree00dfc2a65d64b3f1ffcbfda5bd6b55e57c35f7e7 /kernel/constr.ml
parent94de044826495d8b1d11b9d4b78fb7a7648813e0 (diff)
parenta623c11adac7c34aae92dbeb0c5b7ecc863ce6fd (diff)
Merge PR #7186: Moving `fold_constr_with_full_binders` to a place
Diffstat (limited to 'kernel/constr.ml')
-rw-r--r--kernel/constr.ml21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel/constr.ml b/kernel/constr.ml
index b490aa5092..d7f35da10d 100644
--- a/kernel/constr.ml
+++ b/kernel/constr.ml
@@ -452,6 +452,27 @@ let fold f acc c = match kind c with
| CoFix (_,(_lna,tl,bl)) ->
Array.fold_left2 (fun acc t b -> f (f acc t) b) acc tl bl
+let fold_with_full_binders g f n acc c =
+ let open Context.Rel.Declaration in
+ match kind c with
+ | Rel _ | Meta _ | Var _ | Sort _ | Const _ | Ind _ | Construct _ -> acc
+ | Cast (c,_, t) -> f n (f n acc c) t
+ | Prod (na,t,c) -> f (g (LocalAssum (na,t)) n) (f n acc t) c
+ | Lambda (na,t,c) -> f (g (LocalAssum (na,t)) n) (f n acc t) c
+ | LetIn (na,b,t,c) -> f (g (LocalDef (na,b,t)) n) (f n (f n acc b) t) c
+ | App (c,l) -> Array.fold_left (f n) (f n acc c) l
+ | Proj (_,c) -> f n acc c
+ | Evar (_,l) -> Array.fold_left (f n) acc l
+ | Case (_,p,c,bl) -> Array.fold_left (f n) (f n (f n acc p) c) bl
+ | Fix (_,(lna,tl,bl)) ->
+ let n' = CArray.fold_left2 (fun c n t -> g (LocalAssum (n,t)) c) n lna tl in
+ let fd = Array.map2 (fun t b -> (t,b)) tl bl in
+ Array.fold_left (fun acc (t,b) -> f n' (f n acc t) b) acc fd
+ | CoFix (_,(lna,tl,bl)) ->
+ let n' = CArray.fold_left2 (fun c n t -> g (LocalAssum (n,t)) c) n lna tl in
+ let fd = Array.map2 (fun t b -> (t,b)) tl bl in
+ Array.fold_left (fun acc (t,b) -> f n' (f n acc t) b) acc fd
+
(* [iter f c] iters [f] on the immediate subterms of [c]; it is
not recursive and the order with which subterms are processed is
not specified *)