Referential and value equality operators in Res?

Hi folks.
It looks like === is still a referential comparison in rescript? is that right?
Would a warning be appropriate? I was tripped up to be doing referential comparison on things where I was not otherwise considering ref. Esp weird in using Option which is like a newtype causing ref comparison between inner values.


== is structural equality and almost always what is wanted.

=== is reference (or physical) equality and checks that the LHS and RHS are pointing to the same location in memory and is almost never what is wanted.

People do keep bumping into this issue so a warning is actually a good idea. There is an open PR in the OCaml repository about this: Aliasing == and != with explicit names by thomasblanc · Pull Request #9080 · ocaml/ocaml · GitHub

Fyi, in case you didn’t know, ReScript compiler is a fork of OCaml so it inherits a lot of the implementation.

1 Like

We mention the == / === equality in the Language overview (aka. ReScript / JS comparison table). We should probably add a more thorough doc section on shallow / deep equality somewhere.

EDIT: Actually everything is described in the Primitive Types section, even with concrete examples.

1 Like

I actually like the idea of moving them into stdlib or change the operators from === and !== to something less accessible.