let rec flat_map func = function 
  | head::tail -> merge (flat_map func tail) (func head) 
  | _ -> []