-
-
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
Should true == 1? #15983
Comments
It comes from the fact that |
In a set you'll also run into problems if you want to add How does |
@eschnett Just to be clear, since the julia> Set([NaN, NaN])
Set([NaN])
julia> hash(NaN)
0x15d7d083d04ecb90
julia> hash(1)
0x02011ce34bce797f
julia> hash(true)
0x02011ce34bce797f The |
I was confused; of course, |
note that
in comparing |
Yeah, I think it's even more surprising with > Set([32, ' '])
# Set(Any[' ']) Probably more plausibly encountered in a scenario like: > x = " foo"[1]
# ' '
> Set([32, x])
# Set(Any[' ']) |
Since |
The char vs number thing is definitely a bug left over from when Char was a kind of integer. I'm working on a fix. |
The Char vs. Int comparison thing is surprisingly annoying to fix – we assume that you can compare integers and chars all over the place. I've almost got it done, but it makes me wonder about the change. |
I think it's still the right way to go. Unlike e.g. for real and integer numbers, there is not commonly used abstraction that makes characters a subset of integers. ASCII and UTF-8 are common, but they specify an encoding, not an equivalence. It's easy enough to convert between characters and integers, and if a certain piece of code requires this too often, then I wonder whether there's an abstraction missing. Most other languages -- Python, Fortran, Mathematica -- don't allow such comparisons either. C and its descendents seem to be in the exception. |
"there is not commonly used abstraction that makes characters a subset of integers" .... Unicode? |
In any case, they don't need to be |
Indeed Unicode offers a standard mapping from integer to char, but comparison between these types is still quite confusing. +1 for deprecating it, and requiring people to write |
I don't know... what languages have true character types that don't allow such comparisons? Python doesn't have a character type per se, it only has length-1 strings, and Fortran is similar if I understand it correctly. I don't know about Mathematica, but Mathematica is not particularly well-known for its strength in string processing. In any case, I feel like discussion of |
" it would no longer be possible to have im = Complex(false,true), although we've discussed recently whether that's a good idea." |
it would now be possible to make == with non-comparable items an error since these notions are no longer coupled fix JuliaLang#9381 ref JuliaLang#15983
This is decided and consistent in 1.0: yes, |
@vtjnash recommended I write a bug report after encountering this behavior and looking into workarounds.
At present:
This seems fairly jarring given that the
Bool
type seems much more restrictive than in languages like e.g. Python where implicit promotion/deference to parent methods for comparison are typical. For example, this:Would also imply to me (not necessarily in any formal sense, though) that the prior equality test should also result in a
TypeError
.In this case I want to be able to put both
1
andtrue
in aSet
of typeAny
:But due to hash/equality semantics, only one will make it in. I could return an alternative implementation of
Set
backed by anObjectIdDict
for my use case, which is a serialization library that will convey and receive sets from other languages (whose Boolean equality/hash semantics are heterogenous), but wanted to check in to see if this is the desired behavior, or falling out of some implementation detail.The text was updated successfully, but these errors were encountered: