Add a Repr module to the standard library - #13755
Conversation
db04d84 to
0346afa
Compare
| external ( > ) : 'a -> 'a -> bool = "%greaterthan" | ||
| external ( <= ) : 'a -> 'a -> bool = "%lessequal" | ||
| external ( >= ) : 'a -> 'a -> bool = "%greaterequal" | ||
| end |
There was a problem hiding this comment.
I am in two minds about these submodules.
The main use of them is with numeric types (Int, Int64, Char, maybe String, etc). If anything, monomorphic versions of these operators should be added to those modules. I don't think the operators <, >, <=, >= are very useful in contexts where one is explicitly using a polymorphic compare (since the ordering is implementation-defined). As for = and <>, they are useful, but once you have put them inside a submodule, I don't see myself using a local open to save a few character with respect to Compare.Poly.equal.
In other words, perhaps it would be simpler not to include the Syntax submodules at all (which would also mean that we do not have to discuss what to name the submodule).
There was a problem hiding this comment.
In other words, perhaps it would be simpler not to include the Syntax submodules at all (which would also mean that we do not have to discuss what to name the submodule).
Yes, that would also be my preference to reduce decision fatigue.
There was a problem hiding this comment.
fair enough, that works for me. Done.
0346afa to
9d329b1
Compare
nojb
left a comment
There was a problem hiding this comment.
LGTM
Docstrings need to be added.
And a second official approval is needed to move forward with this PR.
what do you think makes the most sense for this module? Should we copy the docstrings from |
|
Actually it may be nice to do things the other way around, that is, move the stdlib docstrings here and point to this new module in the Stdlib documentation. This paves the way for eventually deprecating |
|
I am not sure about the proposed API: For example, I thought of the following "flat" interface (I'm not saying I strongly prefer it, but I think that throwing some ideas around may help decide how we feel about the API): We loose the information that
|
We could simply have |
In that case, better call the module "Poly". |
|
I think it'd be good to have a name than emphasizes the fact that the behaviour is defined on representations, i.e. that the functions are not parametrically polymorphic, despite their types. |
|
|
|
|
A twist on @nojb's proposal could be: Compare.repr : 'a -> 'a -> int
Compare.repr_equal : 'a -> 'a -> bool
Compare.phys_equal : 'a -> 'a -> bool
Compare.repr_min : 'a -> 'a -> 'a
Compare.repr_max : 'a -> 'a -> 'a |
|
I find the I'm happy to update the PR with the proposal that makes consensus. |
|
I think that there is a tension between having ominous-looking names that make people think twice about using polymorphic comparison, and having pleasant-looking names that encourage people to use them and gradually organize a transition out of In this context I personally find that |
9d329b1 to
9204c53
Compare
|
I've pushed two commits with the updated docstrings to help visualize the two alternative proposals.
|
Well it could be for operations on the representation of values "that you are allowed to use". For example So a synopsis could be: |
One often-requested example: |
|
It seems the principle and latest module layout are accepted by everyone; the current name looks nice to me and doesn’t seem to bother anyone too much. Should we go ahead and merge? |
The protocol says two approval by core devs are needed before merging changes to the standard library. We are not there yet :) |
|
Is So far we had the following proposals which mostly differ on what they invite in terms of future development:
What is the most compelling? Can anyone think of more things that these modules might be suited for? |
Personally I don't see these two as mutually exclusive. |
|
I agree they are not mutually exclusive, and the current functions belong more to I don’t like |
9204c53 to
20a82c5
Compare
Fair enough. I've changed the PR title and implemented the suggestions. How does the PR sound in its current state? I'll rebase in a minute to resolve the conflicts in the changelog and it should be good to go once approved. |
9089321 to
7715a8d
Compare
|
This is still missing a second approval. @nojb Since you have reviewed a previous version of the changes, would you be available to review the new one? |
Thanks for the ping. Semantically, I am in agreement with the PR, but since most of the discussion has revolved around naming choices, which I care very little about, I think someone who is more interested in this aspect of things should make the final call. |
|
I've approved, but have two quick final comments:
|
7715a8d to
40008ee
Compare
done |
|
Sorry to come after the merge, but |
|
I don't think so. It's just that people who want to access the standard library |
|
Indeed, the standard library is essentially opened with a special "weak" open that doesn't shadow existing persisting modules in the environment. |
First proposed in #13753 (comment)
As previously extensively discussed in #9928, #9080 and in many tickets or forum posts, both the physical equality operator
==and the polymorphic comparison functionscompareand=are known footguns for OCaml developers of all levels.Similarly to #9080 / #13753, this PR hopes to be a first step towards a world where OCaml does not have this footgun anymore by encouraging people to use functions from this new module (which is more explicit than using it directly from
Stdliband thus less prone to footgunning), then deprecating==,compare, … when they are less used.Note for reviewers: i'll add documentation to the functions once/if the interface is agreed