Structures and TypeVar

Hi, I want to create a structure like:

struct Lattice{D, L, D1}
    # number of sites per dimension
    L::NTuple{D, Int}
    ...
    sites::Array{Site{L}, D1}
end

where D is just the dimension of the lattice and D1 is D+1. Since D1 is related to D there should be a way of writing this structure without D1, right? Thanks for any help :smiley:

1 Like

The short answer is that there isnโ€™t. The solution StaticArrays uses is to have extra type parameters, but to define a constructor that means users donโ€™t have to use the extra ones.

2 Likes

See ComputedFieldTypes.jl for a simple solution to this also

1 Like