-
-
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
make Bool <: Unsigned (i.e. UInt1) #19168
Comments
Are there any problems caused by not having a completely consistent behavior of |
Would we still allow an idiom like |
That said, Stefan explicitly stated that arthmetic ops like + (used by sum) could stay the same. Overall, I think this is a great move. |
Dispatch ambiguities used to be a big problem but since we don't warn about those anymore, they're less of a problem now. Otherwise, it's just a matter of making it harder to describe and anticipate what generic code is going to do. |
💯 (so many months of Bool mucking about the Integer subtyping tree) |
@JeffBezanson wants to know what problems this change would solve, and I'm drawing a blank. Probably because I've been on an issue triage call for six hours, so if people can post problems this causes, that would be helpful. |
omg -- any new type that subtypes Real pulls in Bool and that (in every case I have encountered) necessitates weird, nonintuitive method dispatch definitions involving Bool to keep the ambiguity away. For me, this has been a real drag all along. And I have other's source with comments like abstract type AbstractLogic end
primitive type Bool < Unsigned 8 end # why should the multivalue true,false be Signed?
abstract type TemporalLogic <: AbstractLogic end
struct AllenLogicalPredicate <: TemporalLogic
...
end |
The ambiguities might arise just from the methods like We have Bool <: Integer, but not <: Signed or Unsigned. Would Unsigned be better? |
yes |
Bool
not a subtype of Number
Resolved:
|
Will |
Ah, that must be what those But, is there any motivation for having that special behavior other than trying to make |
There is some discussion in #22733. |
Ah, nice reference! |
See also #5468. |
I'm experimenting with making
|
what are these intended to convey res1 = op(5, false) ; res2 = div(false, 5)
res1 = op(5, true) ; res2 = op(true, 5)
res1 = op(0x05, false) ; res2 = op(false, 0x05)
res1 = op(0x05, true) ; res2 = op(true, 0x05) |
abstract type Integer <: Real end
abstract type Unsigned <: Integer end
primitive type UInt8 <: Unsigned 8 end
primitive type UInt16 <: Unsigned 16 end
..
abstract type Signed <: Integer end
primitive type Int8 <: Signed 8 end
primitive type Int16 <: Signed 16 end
..
abstract type Logical <: Integer end
primitive type Bool <: Logical 8 end (making it easier to develop through the Logical abstraction) primitive type Tribool <: Logical 8 end # false indeterminant true
primitive type Perhaps <: Logical 8 end # false perhapsnot uninformed perhaps true
primitive type Fuzzy <: Logical 16 end # bit indexed degrees of membership compare primitive type Bool <: Unsigned 8 end # false indeterminant true
primitive type Tribool <: Signed 8 end # false indeterminant true
primitive type Perhaps <: Signed 8 end # false perhapsnot uninformed perhaps true
primitive type Fuzzy <: Unsigned 16 end # bit indexed degrees of membership |
Does this idea include |
If |
I ran into this issue with #22825; it's tough to handle |
Just do |
That's not the reason for the trouble; when determining what thing to sum when summing an iterable, we somehow need to make the decision of whether to promote to system size or not. Inconveniently, because of types that aren't closed under
|
It's fair that |
I don't think we can change Bool arithmetic; that's just too much. The current behavior is useful enough that it's worth special-casing in various places. For this issue, I don't really see enough value in Bool <: Unsigned. |
Original title: "make
Bool
not a subtype ofNumber
"C.f. #18367. I propose simply changing the type hierarchy so that
Bool
is not a subtype ofNumber
since it is so often an exceptional case. We could still keep useful arithmetic behaviors liketrue + true == 2
, etc. – arithmetic need not only work for numbers. Once upon a timeUInt8
+UInt8
produced anInt
, but that's no longer the case, so nowBool
is the "odd man out". If we make!(Bool <: Number)
then we can at least make the behavior ofNumber
completely consistent.The text was updated successfully, but these errors were encountered: