Home > front end >  In Julia what's the difference between dispatching on abstract types versus parametric subset o
In Julia what's the difference between dispatching on abstract types versus parametric subset o

Time:01-24

Are there functional or performance differences between

  • myfunction(x::Real), and
  • myfunction(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 Functions and Varargs (but no other types, myfunction(x::T) where {T} forces specialization.

Other than that, they are exactly the same.

  •  Tags:  
  • Related