Function with argument of generic parametric type, and another argument subtyping the parameter

Hello all,

I’m still trying to understand how generic type dependencies work in Julia. As a follow-up to my question here, I would like to have a dyadic function f(a, b) with the following conditions:

  • a should be a vector-like of tuples (matrix-like of number, String)
  • b should be of a type that subtypes.

For the type of a, per the above question, I’ve settled on AbstractVector{Tuple{M, String}} where M <: AbstractMatrix{<:Number}. This is necessary, because otherwise passing an actual Matrix to the function won’t work. However, this makes the actual element type for the matrix “inaccessible” to specify the type of b.

In the end I found out that a possible solution is to use a nested where specification:

f(a::AbstractVector{Tuple{M, String}}, b::S) where {M <:AbstractMatrix{T}, S<:T} where T <: Number = @show (M, S)

This solution works fine in this trivial case, but in practice, when type T is not going to be used, it will result in the following warning:

WARNING: method definition for f at cde.jl:67 declares type variable T but does not use it.

which I would like to avoid.

Is there a better approach to apply this kind of constraints that I’m missing?

Ah, it seems that the warning arises in the case where all this type deduction happens in optional parameters

which I think I can avoid at least in my case.