In these cases I do the following: (1) Add additional type parameters, as in
```Julia type FooImp{D,D1} baz::Array{D} bar::Array{D1} end ``` (2) Add a function that calculates the type: ```Julia Foo(D) = FooImpl{D,D+1} ``` In many cases I can then have to write `Foo(D)` instead of `Foo{D}` (round parentheses instead of curly braces), but apart from this, things work out nicely. I'm sure there is some `@pure` annotation or similar for `Foo` to help type inference. -erik PS: Yes, it would be nice if this calculation (`D1 = D+1`) could be moved elsewhere, e.g. into the type definition. I don't see why this isn't possible, I think it's mostly a complicated thing to implement, and people haven't demonstrated the necessity for this yet. On Thu, Jun 2, 2016 at 2:07 AM, Robert DJ <math.rob...@gmail.com> wrote: > The problem with not specifying D is type inference. I actually have more > entries in Foo and would like > > type Foo{D} > baz::Array{D} > bar::Array{D+1} > end > > > I want to use Foo in calculations and for D = 1 I am doing something like > > baz + bar[:,1] > baz + bar[:,2] > > > For D = 2: > > baz + bar[:,:,1] > baz + bar[:,:,2] > > > I *could* instead (for D = 2) move the third dimension to extra columns... > > > On Wednesday, June 1, 2016 at 8:56:28 PM UTC+2, Robert DJ wrote: >> >> I have a custom type with a TypePar denoting a dimension and would like >> to define the following: >> >> type Foo{D} >> bar::Array{D+1} >> end >> >> However, this does not work. As D is only 1 or 2 it would OK with >> >> type Foo{1} >> bar::Matrix >> end >> >> type Foo{2} >> bar::Array{3} >> end >> >> but unfortunately this isn't working, either. >> >> Can this problem be solved? >> >> Thanks! >> > -- Erik Schnetter <schnet...@gmail.com> http://www.perimeterinstitute.ca/personal/eschnetter/