Say I have a type that looks the following:
julia> struct Test{T, N, A} <: AbstractArray{T, N}
a::Dict{NTuple{N, Int}, String}
b::Type{T}
c::A
d::Array{T, 2}
function Test{T, N, A}(a, b, c) where {T, N, A}
new(a, b, c, Array{T}(undef, 10, 10))
end
end
I try instantiating it and get a method error
julia> Test(Dict((1,2,3,4)=>"test"), Float64, 6)
ERROR: MethodError: no method matching Test(::Dict{NTuple{4,Int64},String}, ::Type{Float64}, ::Int64)
Stacktrace:
[1] top-level scope at REPL[3]:1
However, an almost identical type with no inner constructor works as I expect:
julia> struct Test2{T, N, A} <: AbstractArray{T, N}
a::Dict{NTuple{N, Int}, String}
b::Type{T}
c::A
d::Array{T, 2}
end
julia> Test2(Dict((1,2,3,4)=>"test"), Float64, 6, Array{Float64}(undef, 10, 10));
Why is this happening? I’m not use I grok the difference and the Julia docs didn’t clear it up for me.
I would like to use the first approach because the field d
is a cache that is automatically created and users shouldn’t have to deal with it.
EDIT: Using Julia 1.2