# Structures and TypeVar

**URL:** https://discourse.julialang.org/t/structures-and-typevar/71518
**Category:** New to Julia
**Tags:** question
**Created:** [November 15, 2021, 6:31pm UTC](https://discourse.julialang.org/t/structures-and-typevar/71518 "2021-11-15T18:31:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![m4ltee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m4ltee/32/30818_2.png) [@m4ltee](https://discourse.julialang.org/u/m4ltee)
#### Post date: [November 15, 2021, 6:31pm UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/1 "2021-11-15T18:31:27Z")

</div>

Hi, I want to create a structure like:

```julia
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 😃

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [November 15, 2021, 7:28pm UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/2 "2021-11-15T19:28:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [November 15, 2021, 7:52pm UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/3 "2021-11-15T19:52:15Z")

</div>

See `ComputedFieldTypes.jl` for a simple solution to this also

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 2, 2022, 3:28pm UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/4 "2022-11-02T15:28:57Z")

</div>

I have the same need…

```julia
mutable struct Foo{N}
    x::Array{Float64,N}
    s::NTuple{N+1,Int64}
    function Foo(arraysize,extradimsize=10)
        nD = length(arraysize)
        x = rand((arraysize...,extradimsize)...)
        s = (arraysize...,extradimsize)
    new{nD}(x,s)
    end
end

```

I am a bit hesitant to add a dependency for it, but on the other side it seems a bit “complex” to use metaprogramming for it… can you just confirm there isn’t a simple solution for it ?

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [November 16, 2022, 5:55am UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/5 "2022-11-16T05:55:50Z")

</div>

There is actually a trivial solution for you (though it does not fully generalize) for adding constants (whereas the original question was about subtraction):

```julia
s::Tuple{Int,Vararg{Int,N}}

```

or, similarly for multiplication:

```julia
t::NTuple{N,NTuple{N,Int}} # total element count is N^2

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 16, 2022, 10:04am UTC](https://discourse.julialang.org/t/structures-and-typevar/71518/6 "2022-11-16T10:04:17Z")

</div>

> [@sylvaticus](#):
>
> can you just confirm there isn’t a simple solution for it ?

There is indeed no way to get rid of an extra parameter to the outer struct if you want to have some type parameter in an inner field that is based on some computation of the outer parameter, no matter how trivial the computation is.
