How to get access to `Map.Tree` in Core v0.15.0?

I’m trying to upgrade core to v0.15.0 today and ran into issues with breaking API changes.

Specifically, the Core.Map.Tree module seems to be gone (is this documented anywhere?). I saw there’s this new Core.Map.Make_tree functor introduced, but I was unable to find any documentations or examples on how it is intended to be used.

For example, say we have this old code that uses core.v0.14.0:

module AMap = Map.Make (A)
module AMapTree = AMap.Tree

How should I migrate this to core.v0.15.0? My initial attempt is this:

(* NOTE: AMap.Tree is no longer available. Downstream references need to be updated. *)
module AMap = Map.Make (A)
module AMapTree = Map.Make_tree (struct
    include A
    include Comparator.Make (A)
  end)

And the corresponding mli signature would be:

module AMap : Map.S with type Key.t = A.t
module AMapTree : module type of struct
    include Map.Make_tree (struct
      include A
      include Comparator.Make (A)
    end)
  end

Is this how the new APIs are supposed to be used? I get the feeling that certain parts of this can be simplified.

Yes, the Tree module was removed from the main functor signatures due to being rarely used and contributing to generating extremely large modules in compiled binaries. You can use Make_tree like you’ve seen, or you can use the Map.Tree module directly.

Thanks for the reply! Followup questions:

  • Is there a simpler way of writing out the module signature of AMapTree? Just duplicating the entire module implementation in the mli file feels less than ideal.
  • Do you know where to find documentation on how one can “use the Map.Tree module directly”?

I also wish that changes like this can be more prominently documented in the release note in the future. But that’s probably feedback for JaneStreet folks.

Make_tree_plain is defined to return a module whose signature is Make_S_plain_tree(Key).S, so you can do something like:

module AMapTree : Make_S_plain_tree(A).S

I don’t think we have specific documentation for this, but Map.Tree’s interface will be similar to AMapTree’s, except that you will have to pass in the comparator manually at each callsite that needs it.

Thanks for the feedback. While we typically try to announce any significant breaking changes, we often miss or omit changes that we expect will not affect any external users. (For example we sometimes search GitHub and other public OCaml code to see if there are any callsites of things we think are more or less unused outside of JS).

I’m guessing in this case that we just thought nobody would be using Tree (in any of its versions) outside of Jane Street, since it’s a pretty specialized module and not a super friendly API.

1 Like