Skip to content
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

what's the deal with Array{T}(::Nothing, ...)? #27700

Closed
JeffBezanson opened this issue Jun 20, 2018 · 5 comments
Closed

what's the deal with Array{T}(::Nothing, ...)? #27700

JeffBezanson opened this issue Jun 20, 2018 · 5 comments
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself missing data Base.missing and related functionality needs decision A decision on this change is needed

Comments

@JeffBezanson
Copy link
Member

I just noticed we have these constructors:

Array{T,N}(::Nothing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), nothing)
Array{T,N}(::Missing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), missing)
Array{T}(::Nothing, d...) where {T} = fill!(Array{T}(undef, d...), nothing)
Array{T}(::Missing, d...) where {T} = fill!(Array{T}(undef, d...), missing)

The odd thing about these is you have to specify an element type, even though there's only one thing it could be --- e.g. you must write Array{Nothing}(nothing, m, n). I propose we do at least one of the following:

  1. Delete these and just use fill instead.
  2. Generalize these so that e.g. MyArray(repeated(x), ...) can be used to construct any array filled with any value.
@JeffBezanson JeffBezanson added needs decision A decision on this change is needed arrays [a, r, r, a, y, s] design Design of APIs or of the language itself labels Jun 20, 2018
@ararslan
Copy link
Member

+1 for deleting those methods in favor of fill

@fredrikekre
Copy link
Member

#25054, #24939

@JeffBezanson
Copy link
Member Author

True, Array{Union{T,Nothing}}(nothing, ...) makes more sense.

@Sacha0
Copy link
Member

Sacha0 commented Jun 20, 2018

+1 for deleting those methods in favor of fill

Never thought I'd see the day 😂

@nalimilan
Copy link
Member

True, Array{Union{T,Nothing}}(nothing, ...) makes more sense.

Yes, that's the whole point of defining these constructors, as fill(nothing, n) returns a Vector{Nothing}, which is very rarely needed. And we don't really want people to use Array{Union{T, Nothing}}(undef, n) instead, whose behavior varies depending on whether T is a bits type. So I think we should keep them.

@nalimilan nalimilan added the missing data Base.missing and related functionality label Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself missing data Base.missing and related functionality needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

5 participants