>
> So in the example above, the type parameter is redundant. However, in the 
> following example, type parameter is not redundant, is it?
>
> ```
> f(x::AbstractArray(Real)) != f{T<:Real}(x::AbstractArray{T}) ?
> ```
>

It is not redundant because parametric types are invariant:
julia> AbstractArray{Float64} <: AbstractArray{Real}
false

julia> Rational{Int64} <: Rational{Integer}
false

>From this you can see that `f(x::AbstractArray{Real})` will only apply to 
arrays where all elements are of type `Real` (e.g. `zeros(Real, 2)`). The 
other definition applies to arrays where all elements are of some concrete 
subtype of `Real` (e.g. `zeros(Float64,2)`, `zeros(Int,2)`, ...).

Best,

Alex.

 

> On Tue, May 5, 2015 at 10:35 AM, Alex <[email protected] 
> <javascript:>> wrote:
>
>> Is the type parameter redundant?
>>>
>>
>> Yes, you always have `AbstractArray{T} <: AbstractArray == true`. See the 
>> section 
>> on parametric abstract types in the manual 
>> <http://julia.readthedocs.org/en/latest/manual/types/?highlight=abstract#parametric-abstract-types>.
>>  
>> This also works for (normal) composite types, e.g. `Rational{Int} <: 
>> Rational == true`.
>>
>> Best,
>>
>> Alex.
>>
>
>

Reply via email to