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

Created on 20 Jun 2018  路  5Comments  路  Source: JuliaLang/julia

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.
arrays decision design missing data

Most helpful comment

+1 for deleting those methods in favor of fill

Never thought I'd see the day 馃槀

All 5 comments

+1 for deleting those methods in favor of fill

25054, #24939

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

+1 for deleting those methods in favor of fill

Never thought I'd see the day 馃槀

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.

Was this page helpful?
0 / 5 - 0 ratings