Instructor: To compare if two values have the same content, we use two equal signs. This is called structural equality. It works with all sorts of data structures, Booleans, tuples, lists, records, and so on.
Structural equality in Reason does a deep comparison. Therefore, we can compare the nested structures, as well. Here, for example, comparing a tuple containing a list with one record.
Using a hash bang and an equal sign checks if two values aren't structurally identical. Referential equality can be checked using three equal signs.
This operator doesn't compare the content, but rather if both values point to the same representation in memory. When binding a value to a name and comparing the name with itself, it is the same reference and results in true.
Here, a comparison of structural equality to referential equality. What to use now?
Most of the time, you will want to use structural equality. The only very few cases where referential equality is useful, one would be comparing mutable props inside shouldComponentUpdate of a React component.
It would be a quick and cheap check, but also might miss if a value with ? this identical content is passed in. In comparison, a lot of deep structural equality checks on large structures could possibly slow down your rendering.
As said, in general, prefer structural equality. My shouldComponentUpdate example is quite a match case, and unless you need 60 frames per second, even structural equality might be fine.
In addition, referential equality has its gotchas. For example, comparing two integers referentially will always result in true to how they are implemented.
Even more so, stay away from referential inequality. It only implies two things are not the same representation in memory. I can't even think of a useful use case.