Clarification on function signature and dispatching behaviour in julia

What's happening here is that Tcan be a datatype and U can be any supertype of string. This the conditions are fulfilled. The thing that was tripping you up with string not being a subtype of int is a red herring since no concrete type is the subtype of any other.


Ok, thanks to laborg it seems I now understand what was going on. If we take this method:

f(a::T, b::U) where {T, U <: T} = "Another Test"

  • 'T' is the "UnionAll" aka "Iterated Union" of all possible types of 'a'.
  • 'U' is the "UnionAll" aka "Iterated Union" of all possible types of 'b' that are subtypes of 'T'

  • What I was misunderstanding was the fact that if (example) a::Int, then T can take a parent abstract type of typeof(a). Since Int <: Any, then T = Any is a valid solution for dispatch.

  • The same for U = Any since String <: Any.

So we now have U <: T that resolves to Any <: Any == true, and the method is called!

I hope I get it :)