# Operations on numerical type parameters

**URL:** https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896
**Category:** General Usage
**Created:** [January 21, 2019, 9:47pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896 "2019-01-21T21:47:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![abraunst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraunst/32/6880_2.png) [@abraunst](https://discourse.julialang.org/u/abraunst)
#### Post date: [January 21, 2019, 9:47pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896/1 "2019-01-21T21:47:39Z")

</div>

I’m sorry if this is a stupid question, but I could not find it in the docs (nor solve it myself). I have a type `A` parametrized with a number `N`. How can I make this work:

```julia
struct A{N}    
    x::Array{Float64, N-1}
    y::Array{Float64, N}
end

```

The problem is of course the `N-1`. Thanks in advance!

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [January 21, 2019, 9:51pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896/2 "2019-01-21T21:51:54Z")

</div>

You can’t really make this work currently, but what you can do is something like this:

```julia
struct A{M,N}
    x::Array{Float64, M}
    y::Array{Float64, N}
    # inner constructor that checks that `M == N-1`
end

```

---

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [January 21, 2019, 10:06pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896/3 "2019-01-21T22:06:13Z")

</div>

You can do it with my forked version of `ComputedFieldTypes`, for which I have a pull-request updating 1.0

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

> <https://github.com/vtjnash/ComputedFieldTypes.jl/pull/4>
>
> don't know if I fixed all the possible issues, but I did update the code based o…n the examples in the README to use the \`where\` syntax for compatibility with Julia 1.0
> 
> Would be good to have this as a registered package, is it going to be registered?
> 
> I would like to use this for a package which I will register.

An example of it in action is [Grassmann.jl](https://github.com/chakravala/Grassmann.jl) I hope it gets registered soon

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [January 21, 2019, 10:28pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896/4 "2019-01-21T22:28:00Z")

</div>

This is a feature we could add eventually; see [https://github.com/JuliaLang/julia/issues/18466](https://github.com/JuliaLang/julia/issues/18466).

---

<div class="post-metadata">

### Author: ![abraunst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraunst/32/6880_2.png) [@abraunst](https://discourse.julialang.org/u/abraunst)
#### Post date: [January 21, 2019, 10:56pm UTC](https://discourse.julialang.org/t/operations-on-numerical-type-parameters/19896/5 "2019-01-21T22:56:15Z")

</div>

Thanks all for the useful replies!
