let rec rev_flat_map func list = function 
  | head::tail -> rev_flat_map func (merge list (func head)) tail 
  | _ -> list