Language Design: Equality & Identity
Part 6: Fixing Rust
Published on 2022-06-09. Last updated on 2025-03-01
Rust designers recognized the issues with Haskell’s approach, but were not able to address the issues with Rust’s Eq
and PartialEq
traits.
The main cause of this failure is the sub-typing relationship between PartialEq
and Eq
:
It requires that an implementation of partial order is consistent with an implementation of total order.
This works for many types, but not for floating point types, for which the IEEE754 standard specifies a partial order as well as a total order.