Variable integer type parameter

question

#1

Consider the definition of the geometrical domain in N-dimensional space, meshed into sub-domains. And if we want to keep its boundary mesh (e.g. for boundary conditions) we would want to write something like this:

type Domain{N}
  volumes :: Array{Float64, N}
  boundaryareas :: Array{Float64, N-1}
  ...
end

(a bit artificial, but it illustrates the problem) Notice, boundaryareas must be one dimension smaller compared to volumes. But currently Julia will throw an error on N-1. Is there any other way to express the idea “I want this to be of dimension N and this of dimension N-1 (or N+1) and this relation should always be satisfied”?


#2

Use two parameters and ensure the invariance in an inner constructor.


#3

On v0.6 you might also want to take a look at the experimental ComputedFieldTypes.jl and the (speculative) issue #18466 on the 1.0 milestone.