Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase compatibility between BatMap, BatSplay and stdlib.Map #1008

Merged
merged 22 commits into from
Feb 1, 2021

Conversation

jabot2
Copy link
Contributor

@jabot2 jabot2 commented Jan 30, 2021

There were several functions added to stdlib.Map, which are added in this PR.
Unfortunately, stdlib also added an update function with an incompatible type signature,
which is why this PR adds an update_stdlib function.

For 100% compatibility, something like module IntMap = struct include BatMap.Int let update = update_stdlib end is necessary, see also the extended batteries_compattest.

Also, for several functions the exception raised on empty maps was changed to Not_found to increase consistency and compatibility with stdlib; the exception raised was unspecified by the documentation for these functions anyways.

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code! I made a first pass of review.

I regret not insisting further to use our proper enumeration type on sets before, because the same issue is showing up again. If you are sure that you don't have the time or knowledge to provide better implementations of these functions, feel free to say so, and I can have a look, but it's actually not so hard to use them, so I think you could give it a try.

src/batMap.mli Outdated Show resolved Hide resolved
src/batMap.mli Outdated Show resolved Hide resolved
src/batSplay.ml Outdated Show resolved Hide resolved
src/batSplay.ml Outdated Show resolved Hide resolved
src/batSplay.ml Outdated Show resolved Hide resolved
src/batSplay.ml Outdated Show resolved Hide resolved
src/batSplay.ml Outdated Show resolved Hide resolved
@@ -79,6 +79,9 @@ module TestMap

val equal : ('a -> 'a -> bool) -> 'a m -> 'a m -> bool

(* true if add, remove, update_stdlib and filter support physical equality *)
val supports_phys_equality : bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nice trick to test this aspect of the Map module, thanks

@jabot2
Copy link
Contributor Author

jabot2 commented Jan 30, 2021

Out of curiosity: what is the oldest ocaml version we still need to support with batteries-included?
Can we (e.g) presume that ppx rewriters are available?

src/batSet.ml Show resolved Hide resolved
@gasche
Copy link
Member

gasche commented Jan 31, 2021

Out of curiosity: what is the oldest ocaml version we still need to support with batteries-included?
Can we (e.g) presume that ppx rewriters are available?

In general I think that the older version that it makes sense supporting is the OCaml version of the current Debian-stable release (or possibly oldstable if it's not too hard). Currently stable has 4.05 and oldstable has 4.02.3. Either of these would be fine.

(On the other hand, using ppx rewriters can introduce a fair bit of maintenance churn/pain, so this is something to decide very carefully.)

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a complete review pass over batMap.ml.

src/batMap.ml Outdated Show resolved Hide resolved
src/batMap.ml Show resolved Hide resolved
src/batMap.ml Outdated Show resolved Hide resolved
src/batMap.ml Outdated Show resolved Hide resolved
Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm done reviewing the PR and I only had somewhat minor comments left. I believe that this is ready for merging; well done!

What kind of a git-history person are you? Would you like to rebase your commits before merging and merge some of them together, or leave things as-is, or that we squash all of them in a single commit?

src/batSet.ml Show resolved Hide resolved
| None -> remove k m)
| None -> add k v m)
m1
m2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is not completely satisfying (it does not preserve the knowledge that we build the result in-order), but here the advice to use merge instead is not so convincing, because merge is okay but not that nice. (It performs an imperative traversal of two Enum, instead of working on the nicer, underlying 'a enumeration structures.) I propose to leave it as-is in the PR, and I maybe submit a subsequent PR to improve merge and then define union from it.

@jabot2
Copy link
Contributor Author

jabot2 commented Jan 31, 2021

Considering git: If you prefer a "clean" history, feel free to squash the commits; I personally don't hold a strong opinion on the matter.

@gasche gasche merged commit a37650e into ocaml-batteries-team:master Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants