-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-safe equality operators #40717
Comments
The best solution is probably to remove the fallback definition where |
You can also use
|
I've made that change in a branch before, and in Core.Compiler.:(==), and found we may rely on the fallback definition sometimes more often than you might think. Perhaps those were often supposed to be |
Here's the old code for deprecating the From forensics, it appears that what killed that change in particular is that we define |
My package IsApprox does something like this. It encodes different notions of closeness in types. One of these types is julia> isapprox(Equal(), 1, 1)
true
julia> isapprox(Equal(), 1, 1 + 1e-15)
false This is free to be given any symantics, and I think erroring when things can't be sensibly compared is best. But, it currently falls back to |
Piggy-backing off of this, should the same be true for |
I do really think that it would have been better to make |
That is how it works inside Core.Compiler |
|
I often make mistakes by using
==
between two objects that I shouldn't be comparing, such as comparing a number to an array of numbers or comparing a string to a character. The==
comparison evaluates tofalse
, but it wasn't the comparison I meant to make. For example,I wish there were an equality-checking operator that would give an error for incompatible types, like in the example above. I'm not sure if the right implementation would be
<:
subtyping relationshipconvert
into each other's typespromote
into a shared typeor something else, or multiple different operators for different purposes. There are plenty of equals-like operators in unicode (eg ≟, ≐). Regardless, the current situation where my mistakes result in silent
false
s causes me problems too often for comfort; I would much rather get an explicit error that I can correct.What would be a good solution here?
The text was updated successfully, but these errors were encountered: