Are there functional or performance differences between
myfunction(x::Real)
, andmyfunction(x::T) where {T<:Real}
?
In this case, Real
is an abstract type which obviously has concrete subtypes like Float64
and Int
.
Are there reasons to prefer one versus the other?
CodePudding user response:
The biggest difference is that you can refer to T
in the function definition. The other difference is that for Function
s and Vararg
s (but no other types, myfunction(x::T) where {T}
forces specialization.
Other than that, they are exactly the same.