The issue here is that this method isn’t for initializing an array with values. It’s only for initializing an array with an “initializer” object, which can be one of undef, nothing or missing, telling Array how to initialize the array initially. This is documented in the docstring of the Array constructor. If you want a zero-dimensional array from a value, you can ues the fill function with a single argument:
Array{Union{Float32,Missing}}(missing, 1,3) is (roughly?) a special syntax for fill!(Array{Union{Float32,Missing}}(undef, 1,3), missing), but the docs don’t really offer a reason to treat these two specially. Is there some optimsation these allow? Trying to time them doesn’t reveal much.
Presumably they cannot be removed before 2.0, but can they be marked as weird discouraged special cases? With a pointer to fill or fill!(... undef ... as the generic thing?
I see, so this is nothing specific to zero-dimensional arrays. It’s true for Arrays generally.
I saw a discussion elsewhere too, but this means that if you want to initialize an array that takes, say Int64, you’ll need to actually create an array that accepts Union{Nothing, Int64}. Seems clunky and confusing, but what do I know?
Also confusing because Array{Int64, 1}() works but Array{Int64, 0}() and Array{Int64, 2}() don’t.
No, you don’t. You can write fill(1, 2, 3) or fill!(Array{Int}(undef, 2, 3), 1). These are the same for all types.
The nothing/missing cases are weird confusing extras.
Array{Int64, 1}() works
This seems to be another weird confusing edge case. (And undocumented?) This array is empty, so perhaps the logic is that the constructor need not care whether you asked for it uninitialised or what. Array{Int64, 1}(undef, 0) would be more standard, or just Int[]. Array{Int64, 2}() does not work; I suppose there are many sizes an empty matrix could have, like fill(99, 0, 1) or fill(99, 3, 0).
@mcabbott I should have said “to initialize a placeholder array that later takes Int64”. I understand that fill works if you already know what you want to put in the array.
I think this is usually called an uninitialised array – you create the array, but don’t initialise its values. This is what undef is for. (And similar.) You should not touch missing/nothing unless you have reason to store those objects in your array.
For anyone interested, here’s some earlier discussion on a similar topic. People smarter than I also tend to think that behavior of Array{Int64, 1}(), Array{Int64, 0}(), Array{Int64, 2}() is inconsistent.