On Apr 29, 2014, at 8:28 AM, Oliver Woodford <[email protected]> wrote:
>
> Are you saying that f{T<:Real}(a::Array{T}) covers both homogeneous and
> heterogeneous arrays, whereas f(a::Array{Real}) only covers heterogeneous
> arrays? If that's the case it strikes me as just as confusing.
This is indeed how parametric types work in Julia.
Array{T} is a family of types, one for each value of T. Defining
f{T}(a::Array{T}) allows you to generically define an infinite number of
functions -- you get a unique function for each value of T.
In contrast, Array{Real} is a single type -- specifically, the type generated
by the parametric type Array{T} when its parameter T = Real. There is no
variable T, so f(a::Array{Real}) defines exactly one function -- and that
function accepts exactly one type of input.
Array{Any} is also a single type.
-- John