Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sorry, I should have said compare values of-this-type. I was focused on the fact that type does matter here, which as you show the equals method is called on key, not some arbitrary system-wide equals method but a method defined on key's type.

Rust has a magic unstable trait StructuralEq which means not only are we promised that values of this type can be compared for equality (that's what Eq does) but that comparison will just be a bitwise memory comparison. Lots of useful things are not StructuralEq even if they are Eq

Apparently Java's Floats also do the same canonicalisation for equals(). So in effect in Java although NaN != NaN, once you box it that ceases to be true. This seems like a spectacularly bad idea to me, but presumably it made somebody's awful hack work at one point.



> This seems like a spectacularly bad idea to me, but presumably it made somebody's awful hack work at one point.

but elsewhere you say, "You are welcome to build a type which has this property and declares that it is Eq". This is exactly the difference between double and Double in Java. double has the `==` operator that isn't reflexive and works as required by IEEE-754 and Double has Double.equals, which is documented[1] to be a reflexive, transitive, symmetric, consistent, and substitutable relation.

[1]: https://docs.oracle.com/en/java/javase/17/docs/api/java.base...


Is it clearer if I explain that you are welcome to do things which are a spectacularly bad idea ?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: