January 2020
Intermediate to advanced
532 pages
13h 31m
English
When we define a parametric method, we use the where clause to introduce type variables. Let's go over a simple example:
triple(x::Array{T,1}) where {T <: Real} = 3x
The triple function takes an Array{T}, where T is any subtype of Real. This code is very readable, and it is the format that most Julia developers choose to specify type parameters. So what could the value of T be? Could it be a concrete type, abstract type, or both?
To answer this question, we can test it out from the REPL:

So the method does get dispatched on both the abstract type (Real) and concrete type (Int64). It is worth mentioning that the
Read now
Unlock full access