[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-06 Thread Jeffrey Sarnoff
That the Union does not work (and that reasonable people have written the example expecting the Union to work) is good feedback -- a surprise where Julia is motivated to become unsurprising. Julia requires there to be two distinct outer method signatures (Na != Nb, T1 != T2) to absorb

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-06 Thread 'Greg Plowman' via julia-users
Actually, I'm totally wrong. The Union won't work. Sorry for bad post. On Wednesday, April 6, 2016 at 1:52:15 PM UTC+10, Greg Plowman wrote: > > A workaround would be to have two methods, one for the homogeneous >> elements in the first parameter, as you suggest, and a second for a vector >> w

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-05 Thread 'Greg Plowman' via julia-users
> A workaround would be to have two methods, one for the homogeneous > elements in the first parameter, as you suggest, and a second for a vector > with homogeneous elements in both parameters, with both T, N specified in > the signature. But I have to write an extra method... > As pointed ou

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-04 Thread Jeffrey Sarnoff
If I understand your question, you want to accept e.g. both [Foo{Int,2}((1,2)), Foo{Int,2)((2,3))] and [Foo{Int,2}((1,2)), Foo{Int,3)((2,3,4)) ] and then do something with them, and you want to reject e.g. [Foo{Int,2((1,2)), Foo{Float64,2}((2.0,3.0))]. Having two method signatures that

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-04 Thread Tomas Lycken
The reason you’re getting that method error is because of type parameter invariance - in short, even though F <: Foo{T}, we *don’t* have Vector{F} <: Vector{Foo{T}}. Until triangular dispatch lands, defining

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-04 Thread Davide Lasagna
Thanks, yes, I have tried this, but did not mention what happens. For the signature you suggest, you get a `MethodError` in the case the vector `x` is homogeneous in both parameters. Look at this code type Foo{T, N} a::NTuple{N, T} end function make_homogeneous_Foos(M) fs = Foo{Float64

[julia-users] Re: enforcing homogeneity of vector elements in function signature

2016-04-04 Thread John Myles White
Vector{Foo{T}}? On Monday, April 4, 2016 at 1:25:46 PM UTC-7, Davide Lasagna wrote: > > Hi all, > > Consider the following example code > > type Foo{T, N} > a::NTuple{N, T} > end > > function make_Foos(M) > fs = Foo{Float64}[] > for i = 1:M > N = rand(1:2) > f = Foo{Fl