(* remove l x is l with any occurrence of x removed. Requires: l contains no duplicates. *) let rec remove l x = match l with [] -> [] | h::t -> if h = x then t else h :: (remove t x) (* union l1 l2 is a list containing one copy of each of the elements of l1 and l2. Requires: l1 and l2 contain no duplicates. *) let rec union l1 l2 = match l1 with [] -> l2 | h::t -> if List.exists (fun x -> x = h) l2 then union t l2 else h::(union t l2) type exp = Var of string | App of exp * exp | Lam of string * exp let rec fv(e: exp): string list = match e with Var s -> [s] | App (e1, e2) -> union (fv e1) (fv e2) | Lam (x, e) -> remove (fv e) x let e1 = App (Var "x", Var "x") let sa = Lam ("x", e1) let omega = App(sa, sa)