Multiple dispatch unexpected function call

Here’s what I find surprising about this behaviour that I’m surprised hasn’t been focused on more: f(c1::Concrete{T}, c2::Concrete{T}) where T is applicable to only a diagonal subset of types.

E.g. if we have N possible type parameters, then

f(c1::Concrete, c2::Concrete)

could have N^2 possible specializations, whereas

f(c1::Concrete{T}, c2::Concrete{T}) where T

only has N possible specializations because it requires that the parameters match. To me, this means that this method is strictly more specific and hence should be prioritized by dispatch.

4 Likes