let list_remove_doubles ?(pred=(=)) l = List.fold_left (fun acc e -> if List.exists (pred e) acc then acc else e :: acc) [] (List.rev l)