Inner parametric type constructor not defined error

I have the following parametric type newInt, which works, but adding an inner constructor that fills in certain fields causes errors:

struct newInt{U,V}
    u::U
    v::V
    n::DataType
end

julia> newInt(10,"a",String)
newInt{Int64,String}(10, "a", String)

struct newInt2{U,V}
    u::U
    v::V
    n::DataType
    newInt2{U,V}(u::U,v::V) where {U,V} = new(u,v,typeof(v))
end

julia> newInt2(10,"a")
ERROR: MethodError: no method matching newInt2(::Int64, ::String)

Inner constructor defined in such a way, that you need to use following construction

newInt2{Int, String}(10, "a")

But you do not need inner constructor at all, you can define usual outer constructor

newInt2(u::U,v::V) where {U,V} = newInt2(u,v, V)
1 Like