# Parametric type with numbers

**URL:** <https://discourse.julialang.org/t/parametric-type-with-numbers/74544>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [January 13, 2022, 12:02pm UTC](https://discourse.julialang.org/t/parametric-type-with-numbers/74544 "2022-01-13T12:02:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Post date:** [January 13, 2022, 12:02pm UTC](https://discourse.julialang.org/t/parametric-type-with-numbers/74544/1 "2022-01-13T12:02:41Z")

</div>

Hello!

I am having difficulties trying to model the adequate code for what I want to achieve.  
Imagine I have the following struct:

```julia
struct Device
    a::NTuple{3,Float64}
    b::NTuple{2,Float64}
end

```

where `b` is always going to be one element shorter than `a`. How can I generalize this for `N`?

I figured that it would be something like

```julia
struct Device{N}
    a::NTuple{N,Float64}
    b::NTuple{N-1,Float64}
end

```

but it errors because I cannot perform substraction on types.

Thanks!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 13, 2022, 12:15pm UTC](https://discourse.julialang.org/t/parametric-type-with-numbers/74544/2 "2022-01-13T12:15:38Z")

</div>

I think Matt’s answer here is still right:

[https://stackoverflow.com/questions/34073243/expressions-depending-on-integer-type-parameters-in-type-definitions-in-julia-ar](https://stackoverflow.com/questions/34073243/expressions-depending-on-integer-type-parameters-in-type-definitions-in-julia-ar)

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 13, 2022, 12:23pm UTC](https://discourse.julialang.org/t/parametric-type-with-numbers/74544/3 "2022-01-13T12:23:13Z")

</div>

There is [GitHub - vtjnash/ComputedFieldTypes.jl: Build types in Julia where some fields have computed types](https://github.com/vtjnash/ComputedFieldTypes.jl) which helps with this. There is also a github issue around this [https://github.com/JuliaLang/julia/issues/18466](https://github.com/JuliaLang/julia/issues/18466)

---

<div class="post-metadata">

**Author:** ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Post date:** [January 13, 2022, 6:52pm UTC](https://discourse.julialang.org/t/parametric-type-with-numbers/74544/4 "2022-01-13T18:52:49Z")

</div>

Thank you both!!
