-
-
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
Broaden array constructor to allow any fill value #41562
base: master
Are you sure you want to change the base?
Conversation
It seems odd to me that `Array{Union{Missing, T}}(missing, n...)` and `Array{Union{Nothing, T}}(nothing, n...)` exist but the more general case `Array{T}(x::T, n...)` does not. There are some potential issues I'm sure. Notably it makes `Array{T}(undef, n...)` seem even more of an odd one out, rather than just the only strange one out of three options (the other two being `nothing` and `missing`. But I'm inclined to think this reduces the inconsistency since there are only two options, `x::UndefInitializer` and `x::T`.
See #24595 and a bunch of linked issues/PRs in there. |
I believe this syntax was actually proposed by you (4 years ago) deep in that issue. This seems like a relatively limited subset of the proposal(s) there, while still allowing for all the extensions by restricting the type of |
I am sure, but that's not really a convincing argument. In particular, this PR makes it impossible to ever support something like |
Another issue is that the 0-d case is ambiguous, e.g. |
Oh, no I was just noting that.
Isn't the type restriction sufficient?
I think this is the same right? The other array isn't type |
I don't think it's a good idea for this to depend on the element type, but we could disambiguate it by requiring a dimension argument, e.g. |
So it should (hypothetically) be broadened further to |
Ideally everything should work the same if the element type is widened; e.g. |
It seems odd to me that
Array{Union{Missing, T}}(missing, n...)
andArray{Union{Nothing, T}}(nothing, n...)
exist but the more general caseArray{T}(x::T, n...)
does not.There are some potential issues I'm sure. For one it makes
Array{T}(undef, n...)
seem even more of an odd one out, rather than just the only strange one out of three options (the other two beingnothing
andmissing
). But I'm inclined to think this reduces the inconsistency since there are only two options,x::UndefInitializer
andx::T
after the change.