# Operation with struct parameter within struct definition

**URL:** <https://discourse.julialang.org/t/operation-with-struct-parameter-within-struct-definition/130261>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 26, 2025, 11:22pm UTC](https://discourse.julialang.org/t/operation-with-struct-parameter-within-struct-definition/130261 "2025-06-26T23:22:15Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [June 27, 2025, 12:00am UTC](https://discourse.julialang.org/t/operation-with-struct-parameter-within-struct-definition/130261/4 "2025-06-27T00:00:59Z")

</div>

From one of the “Related” threads that Discourse suggested below here:

> [@Arithmetic for parametric type values in structs e.g., N+1](https://discourse.julialang.org/t/arithmetic-for-parametric-type-values-in-structs-e-g-n-1/110925/4):
>
> I would do the following. julia\> struct Foo{N,M} arr1::Array{Float64, N} arr2::Array{Float64, M} Foo{N}(a,b) where N= new{N, N+1}(a,b) end julia\> Foo{1}(rand(2), rand(2,3)) Foo{1, 2}([0.9165330134722103, 0.8133055136507046], [0.15120619990261142 0.8543356012671888 0.5239972992036701; 0.12074486400173157 0.6817097391005016 0.3327645622931258])

Still uses an extra type parameter, but the constructor definition neatly makes it so that the redundant parameter doesn’t have to be explicitly given during struct instance initialization.

Another related thread recommended [GitHub - vtjnash/ComputedFieldTypes.jl: Build types in Julia where some fields have computed types](https://github.com/vtjnash/ComputedFieldTypes.jl)

---

_[View the full topic](https://discourse.julialang.org/t/operation-with-struct-parameter-within-struct-definition/130261)._
