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.

https://rescript-lang.org/try?code=LYewJgrgNgpgBAIQgF2SAdnAvHA3gKDjgAEAnGAQwGNkA6KkYABwxnWULlmTmAoGt4OABQA-BhHYAuOAEt2ASmwA+PJyLc4AD2x4ARAAsKRvTIDMAX3VcYPAJ67ch4xVNxL1zULgBlRjGEtJSwQ339hOwVPWzgAM10-YACg7BxEgMjonmRZJIBnXTyAd1lkKgM4CXY1IiIAHzgARhU4PQwqGD1rBoAmFr1kEo6u2rgGzFl4oVU9AFEARQBVAEEAGRHa8ZaEGCg6AEl2WjQfZFJ5AHNhdCUAalvWuBz8jaIrUc1gPIvdPQBhKCyKj8XjwPRwe5PXIwPL4awAHgARig0OhVLgvhcALTKABKlBotDyZ0uFjg8IA9MjUBhlJwrFYgA

Thanks
A

== 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.