Of course, thank you Mauro.
For the purposes of readability, is there any syntax by which I can avoid
explicit parameterisation of the function? I am thinking of something like
this:
function fun(arr::Array{<:Type3, 1})
end
S.
On Tuesday, 2 February 2016 06:27:10 UTC, Mauro wrote:
>
> On Mon, 2016-02-01 at 18:29, Samuel Powell <[email protected]
> <javascript:>> 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])
>