-
Notifications
You must be signed in to change notification settings - Fork 30
Array.sort: compare function return type #74
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
Comments
|
I don't see how it's really more generic. Also, having to deal with NaN > 0 // false
NaN < 0 // false
NaN == 0 // false
NaN == NaN // false From a perspective of both simplicity and practicality it seems to me that it would be better to stick with |
What I meant is that, with a float result, both
Is it guaranteed that an |
Float is not as first class as int, in terms of learning curve and primitives. One ends up in the dotted variants of operations etc. |
Good points. Sounds to me like |
Yes, good points, thanks for the answers. Will close this issue. |
Currently, the compare function for
Array.sort
/Array.sortInPlace
is typed asI do realize that this is also the signature used in OCaml's compare functions, but I wonder if the return type shouldn't be
float
instead for the ReScript/JS world. Looking at the MDN documentation for Array.sort, there is no need for the return type to be an integer, it is just about > 0, < 0 or === 0.Using
float
instead ofint
would be more generic and allow us e.g. to use(a, b) => a -. b
as a compare function for floats.What do you think?
The text was updated successfully, but these errors were encountered: