-let empty_lenv = Null
-
-let push f es ?c b =
- let es = Cons (es, c, b) in f es
-
-let get err f es i =
- let rec aux j = function
- | Null -> err ()
- | Cons (tl, None, b) when j = 0 -> f tl b
- | Cons (_, Some c, b) when j = 0 -> f c b
- | Cons (tl, _, _) -> aux (pred j) tl
- in
- aux i es
-
-let rec rev_iter f map = function
- | Null -> f ()
- | Cons (tl, None, b) ->
- let f _ = map f tl b in rev_iter f map tl
- | Cons (tl, Some c, b) ->
- let f _ = map f c b in rev_iter f map tl
-
-let rec fold_left f map x = function
- | Null -> f x
- | Cons (tl, _, b) ->
- let f x = fold_left f map x tl in
- map f x b
+let empty = Null
+
+let push e c a b = Cons (e, c, a, b)
+
+let rec get i = function
+ | Null -> Null, Null, [], Void
+ | Cons (e, c, a, b) when i = 0 -> e, c, a, b
+ | Cons (e, _, _, _) -> get (pred i) e
+
+let get e i = get i e
+
+(* used in BrgOutput.pp_lenv *)
+let rec fold_right f map e x = match e with
+ | Null -> f x
+ | Cons (e, c, a, b) -> fold_right (map f e c a b) map e x
+
+(* used in MetaBrg.unwind_to_xlate_term *)
+let rec fold_left map x = function
+ | Null -> x
+ | Cons (e, _, a, b) -> fold_left map (map x a b) e