Hi,
As typeof(1) == Int64
, we have 1 isa UInt == false
However, this makes it difficult to pass a default value:
f(x::UInt = 1) = 2
f()
# MethodError: no method matching f(::Int64)
Sure, I can define:
f(x::UInt = UInt(1)) = 2
but it’s ugly…
DD
It would be a really bad idea for 1
to default to UInt
I would not expect this to change. Otherwise 1 - 3
would be type unstable or have integer underflow.
1 Like
There is a literal syntax for UInt64
, but it is more verbose than typing UInt(1)
:
julia> 0x0000000000000001 == UInt(1)
true
1 Like
True…
But the issue here is handling of default parameters.
Why not automatically convert those? They are constants, so this can be done at compile time.
Yeah, open an issue for conversion of literals in defaults. That would be a little magical, but that could happen in that specific context (reminiscent of literal_pow
). But the general topic here, 1 is not a UInt
, I think is a done deal.
1 Like