I would like to have a type such as this:
type foo{T,M,N} 
    x::Array{T,M} 
    y::Array{T,N} 
end 

Where T and M can be anything, but N = M + 1.  I know I can't write

type foo{T,M} 
    x::Array{T,M} 
    y::Array{T,M+1} 
end 

So I wrote the following naive code, but I get an error:

julia> function foo{T,M,N}(x::Array{T,M}, y::Array{T,N}) 
    @assert (M + 1) == N 
    return foo(x,y) 
end 
foo{T,M,N} (constructor with 1 method) 

julia> foo(rand(3),rand(3,3)) 
ERROR: stack overflow 
in foo at none:2 
in foo at none:3 (repeats 79999 times)

I have two questions:

1. How can I correctly implement an assert on the parameters of the default 
constructor?  

2. Is there a more elegant way to constrain type parameters other than an 
assert in the constructor?

Thanks!

Reply via email to