let rec vars_of a = match a with | Var _ -> Set.singleton a | App(_, al) -> List.fold_left (fun acc b -> Set.union (vars_of b) acc) Set.empty al