Array(Float64, 3)
in 0.6 should be Array{Float64}(3)
.
If I wanted to make a type that, say, wraps an Array and also stores its length, I can:
mutable struct Wrap{A <: Array{T, 1} where {T}}
a::A
l::Int64
end
If I want to use the old syntax (Wrap(Float64, n)
) to construct this wrapped array, then I can:
function Wrap(T, n)
Wrap(Array{T}(n), n)
end
But I don’t see any way to use the following syntax Wrap{Float64}(n)
to construct the type above.
If I do want that syntax to be available, (in order to be consistent with Array
) I can by including an additional type parameter, and with an inner constructor as follows
mutable struct Wrap{T, A <: Array{T, 1}}
a::A
l::Int64
function Wrap{T}(n) where {T}
new{T, Array{T, 1}}(Array{T}(n), n)
end
end
are there any other options? The first approach seems less complicated, except that it doesn’t look like how you construct Array
.
(And if I want to dispatch on the eltype
of the a
field, I would need the repeated T
in any case (as of today), right?)