let rec fold f a acc =
  match a with
    | Var _ -> f a acc
    | App(_, l) -> f a (List.fold_right (fold f) l acc)