After browsing through Rescript's API, it seems like there is no function that compares 2 strings that returns a boolean. The best option is localeCompare
but it behaves somewhat different from the JS's ==
. Why does localeCompare
return a float instead of an integer?
Asked
Active
Viewed 294 times
1

heiheihang
- 82
- 9
1 Answers
1
You can compare strings using ==
in rescript as well. Alternatively there is a String.equal
as well if you need a function restricted to strings specifically, The "native" (non-Js
) standard library modules such as String
unfortunately seems to be left out of the rescript documentation entirely.
localeComapre
probably returns a float
because it might be possible for it to return non-integer numbers. JavaScript unfortunately has no integer type, which makes it hard to know if it could return float
s even if it seems obvious that it shouldn't. I've seen several of this kind of bugs myself in various bindings.

glennsl
- 28,186
- 12
- 57
- 75
-
Thanks for the answer. After browsing carefully, I do not see String.equal in Rescript's JS API, do you mind double checking this? – heiheihang Dec 23 '20 at 05:47
-
It isn't in the `Js` API. It's part of OCaml's standard library, which rescript builds on, and is documented [here](https://caml.inria.fr/pub/docs/manual-ocaml/libref/Stdlib.String.html). note that rescript is based on the 4.06 release of OCaml (last time I checked). Anything added after that won't be available. – glennsl Dec 23 '20 at 13:28