PartialEq and is_nan

I was thinking about how NAN is responsible for the existence of the PartialEq. Floating point types are already providing a is_nan method. Now wouldn’t it make sense to have some is_unequatable(&self) -> bool method directly in the trait PartialEq to identify values that are different from themselves? Of course x != x is always possible but it’s not that readable and the raison d’etre of is_nan methods is typically to avoid this kind of awkward comparison.

There’s more than just NAN, though, so I’m unsure how helpful it’d be generically.

Imagine an enum Either<TL,TR> { Left(TL), Right(TR) }. That should be only PartialEq even if TL:Eq and TR:Eq because the two sides are incomparable: Left(0) != Right("A") even though Left(0) == Left(0) and Right("A") == Right("A").

I’m afraid I don’t understand your point. If both TL and TR are Eq your enum can perfectly be Eq. An “unequatable” value would be a value that is not equal to itself (and applying axioms in the doc not equal to any value of the type).

My apologies; you’re absolutely right. I was thinking PartialOrd (!(Left(0) < Right("A")) && !(Left(0) > Right("A")) && !(Left(0) == Right("A"))), not PartialEq.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.