On Mon, 2016-02-01 at 18:29, Samuel Powell <s...@samuelpowell.co.uk> wrote:
> Hi,
>
> Consider the following:
>
> abstract TypeA
>
> type Type1 <: TypeA
> end
>
> type Type2 <: TypeA
> end
>
> type Type3{T<:TypeA}
> prof::T
> end
>
> function fun(arr::Array{Type3, 1})
> end
>
> t1 = Type1()
> t2 = Type2()
>
> t3_1 = Type3(t1)
> t3_2 = Type3(t2)
>
> fun([t3_1; t3_2]) # This is fine
> fun([t3_1; t3_1]) # This fails with a no method error
> fun([t3_2; t3_2]) # This fails with a no method error

This is because of invariance (search the doc or julia-users for it):

julia> Array{Type3{Type1}}<:Array{Type3}
false

This works:

julia> function fun{T<:Type3}(arr::Array{T, 1})
       end
fun (generic function with 2 methods)

julia> fun([t3_1; t3_1])

Reply via email to