[SOLVED] In Julia what's the difference between dispatching on abstract types versus parametric subset of abstract types?

Issue

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?

Solution

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.

Answered By – Oscar Smith

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *