method private sort_elements l =
      match compare_function with
        None -> l
      |        Some f -> List.sort f l