+ let rec reloc_subst subst = function
+ | (Terms.Leaf _) as t -> t
+ | Terms.Var i ->
+ (try
+ List.assoc i subst
+ with
+ Not_found -> assert false)
+ | (Terms.Node l) ->
+ Terms.Node (List.map (fun t -> reloc_subst subst t) l)
+;;
+
+ let rec apply_subst subst = function
+ | (Terms.Leaf _) as t -> t
+ | Terms.Var i ->
+ (match lookup i subst with
+ | Terms.Node _ as t -> apply_subst subst t
+ | t -> t)
+ | (Terms.Node l) ->
+ Terms.Node (List.map (fun t -> apply_subst subst t) l)
+;;
+
+ let flat subst =
+ List.map (fun (x,t) -> (x, apply_subst subst t)) subst
+;;
+
+ let concat x y = x @ y;;