What is the difference bewtween these two types? ::Vector{GMTdataset{_A, 2} where _A<:Real} and ::Vector{<:GMTdataset{T, 2}}; ...) where T<:Real

Hi,

I’m puzzled with this method failure. There must be one difference because it errors with, but I really can’t figure what.

typeof(D)
Vector{GMTdataset{_A, 2} where _A<:Real} (alias for Array{GMTdataset{_A, 2} where _A<:Real, 1})

julia> GMT.line2multiseg(D)
ERROR: MethodError: no method matching line2multiseg(::Vector{GMTdataset{_A, 2} where _A<:Real})

Closest candidates are:
  line2multiseg(::Vector{<:GMTdataset{T, 2}}; is3D, color, auto_color, lt, color_col) where T<:Real
   @ GMT c:\Users\j\.julia\dev\GMT\src\utils_types.jl:1236
1 Like

The T<:Real in that where clause demands a value (from the parameter S as I renamed below in an analogous Ref example) that _{_A} where _A<:Real just doesn’t provide. The two types are actually disjoint subtypes of a known wider type.

julia> (Vector{<:Ref{T}} where T<:Real) == (Vector{S} where {T<:Real, S<:Ref{T}}) # I dislike the <: shorthand
true

julia> Vector{Ref{_A} where _A<:Real} <: (Vector{S} where {T<:Real, S<:Ref{T}}) # why dispatch fails
false

julia> typeintersect(Vector{Ref{_A} where _A<:Real}, (Vector{S} where {T<:Real, S<:Ref{T}}))
Union{}

julia> Vector{Ref{_A} where _A<:Real} <: (Vector{S} where S<:(Ref{T} where T<:Real))
true

julia> (Vector{S} where {T<:Real, S<:Ref{T}}) <: (Vector{S} where S<:(Ref{T} where T<:Real))
true

Thanks for looking into this contrived case. Meanwhile I investigated more and found, less abstractly, why it failed.

The GMTdatset type is defined as GMTdataset{T<:Real, N}

and I had a test that loosely created a vector of them mixing Ints and Floats

julia> D = [mat2ds([-1 -1; 1 1; 1 -1; -1 -1]), mat2ds([1.5 1.0; 1.5 1.5; 2.0 1.0; 1.5 1.0])];

julia> typeof(D)
Vector{GMTdataset{T, 2} where T<:Real} (alias for Array{GMTdataset{T, 2} where T<:Real, 1})

julia> D = [mat2ds([-1.0 -1; 1 1; 1 -1; -1 -1]), mat2ds([1.5 1.0; 1.5 1.5; 2.0 1.0; 1.5 1.0])];

julia> typeof(D)
Vector{GMTdataset{Float64, 2}} (alias for Array{GMTdataset{Float64, 2}, 1})

when I recently parameterized one function that accepts Vector{GMTdataset{T,2}... I started to get that error. Fixing the type mix solved the issue but the Julia error message was not clear at all to me (as you could testify).