Suppose you have a function which takes a type as argument, say for example convert function. If you want to constrain this type, idiomatic Julia seems to be the following:
convert(::Type{T}, x::Foo) where {T <: Integer}
However, as far as I understand, one could just as well write this as:
convert(T::Type{<:Integer}, x::Foo)
which at least to my eyes reads much cleaner. However, I’ve never seen this in the wild.
Is there a compelling reason to prefer the idiomatic (top) version?
Strictly speaking, these are more equivalent argument names:
convert(S::Type{T}, x::Foo) where {T<:Integer} = ... # body can use S or T
convert(S::Type{T} where {T<:Integer}, x::Foo) = ... # body can use S
Only the first makes the method share that parameter. One use is making multiple type annotations share that parameter, like foo(::Type{T}, t::T) where T. As mentioned before, It also helps force specialization with respect to that argument in the exceptional cases that Julia doesn’t do it for you, specifically when the argument has a type Type, Function, or Vararg.