The problem is not the values, the problem is the physical equality == . Its meaning is implementation dependent, with the exception of certain specific warranties.
In a typical OCaml implementation, floating values ββare inserted into the box, so it is normal if no two float values ββare physically equal.
Conversely, int values ββare not placed in the box, so two equal int values ββwill be physically equal.
Physical equality cannot be used unless you are sure you know what you are doing. It violates many of the desired properties of a functional language, such as referential transparency, as in this case.
Update : specific guarantees for the value == are given by Pierre Chambard in his excellent answer.
source share