# Type parameters which depend on other type parameters

**URL:** <https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769>\
**Category:** New to Julia\
**Tags:** parametric-types\
**Created:** [April 17, 2020, 3:58pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769 "2020-04-17T15:58:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [April 17, 2020, 3:58pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769/1 "2020-04-17T15:58:23Z")

</div>

Is there a way to specify a type parameter in a way that depends on another type parameter?

For example, a StaticMatrix takes in types `{M,N,T,L}`, where `M,N` are dimensions and `L` is the length of the array. Is there a way to set `L=M*N`? For example, if I try to define

```julia
struct foo{N <: Integer}
    A::SMatrix{N,N,Float64,N*N}
end

```

I get the error

```julia
ERROR: MethodError: no method matching *(::TypeVar, ::TypeVar)

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 17, 2020, 4:25pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769/3 "2020-04-17T16:25:52Z")

</div>

Sorry, my last comment did not attack exactly your case, but I am also having the problem, it really seems that inside a struct definition the `N` is a typevar, has no `*` defined for it, even if after a instance of a concrete type like `Foo{10}` is able to get the value and make use of it.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 17, 2020, 4:36pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769/4 "2020-04-17T16:36:41Z")

</div>

[GitHub - vtjnash/ComputedFieldTypes.jl: Build types in Julia where some fields have computed types](https://github.com/vtjnash/ComputedFieldTypes.jl) makes this a bit easier to deal with.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [April 17, 2020, 5:42pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769/5 "2020-04-17T17:42:22Z")

</div>

If all you want is to guarantee its a square matrix, you don’t need to compute that last entry yourself, just do,

```julia
struct foo{N, SM<:SMatrix{N,N,Float64}}
    A :: SM
end

```

(note also its just `N` instead of `N <: Integer`).

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [April 17, 2020, 5:45pm UTC](https://discourse.julialang.org/t/type-parameters-which-depend-on-other-type-parameters/37769/6 "2020-04-17T17:45:18Z")

</div>

@marius311 - thank you! This solves my specific problem.

@rdeits - thanks, I didn’t know about this package.
