+let abst a w = Abst (a, w)
+
+let abbr a v = Abbr (a, v)
+
+let lref a i = LRef (a, i)
+
+let cast a u t = Cast (a, u, t)
+
+let appl a u t = Appl (a, u, t)
+
+let bind b t = Bind (b, t)
+
+let bind_abst a u t = Bind (Abst (a, u), t)
+
+let bind_abbr a v t = Bind (Abbr (a, v), t)
+
+(* local environment handling functions *************************************)
+
+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