# Parametric struct with key arguments

**URL:** <https://discourse.julialang.org/t/parametric-struct-with-key-arguments/107374>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 10, 2023, 3:05am UTC](https://discourse.julialang.org/t/parametric-struct-with-key-arguments/107374 "2023-12-10T03:05:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [December 10, 2023, 3:05am UTC](https://discourse.julialang.org/t/parametric-struct-with-key-arguments/107374/1 "2023-12-10T03:05:08Z")

</div>

```julia
struct SortedParticleList{N,M,T<:Unsigned}
    storage::SVector{N,T}
end

```

Here we have a parametric struct with three position arguments. I can have

```julia
SortedParticleList{N}

```

and

```julia
SortedParticleList{N, M}

```

and

```julia
SortedParticleList{N,M,T}

```

but not

```julia
SortedParticleList{M}

```

right? Can we have key arguments for struct definition?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 10, 2023, 3:16am UTC](https://discourse.julialang.org/t/parametric-struct-with-key-arguments/107374/2 "2023-12-10T03:16:17Z")

</div>

No, but you can create aliases. Some [common aliases in use are `Vector` and `Matrix`](https://github.com/JuliaLang/julia/blob/84cfe04e7f149235cbb903cc6f4110ddaa7007eb/base/array.jl#L60-L71).

```julia
const Vector{T} = Array{T,1}
const Matrix{T} = Array{T,2}

```

I’ve have wanted a `N` version of this. You could write that as follows.

```julia
const NArray{N,T} = Array{T,N}

```

In use, this would be as follows.

```julia-repl
julia> const NArray{N,T} = Array{T,N}
Array{T, N} where {N, T}

julia> NArray{1}
Vector (alias for Array{T, 1} where T)

julia> NArray{2}
Matrix (alias for Array{T, 2} where T)

julia> NArray{3}
Array{T, 3} where T

```

Another way to write this as follows.

```julia-repl
julia> const MArray{M} = Array{<: Any,M}
Array{<:Any, M} where M

julia> MArray{2}{Int}
Matrix{Int64} (alias for Array{Int64, 2})

julia> MArray{2, Float64}
Matrix{Float64} (alias for Array{Float64, 2})

```

So you could do as follows.

```julia-repl
julia> const SortedParticleListM{M, T, N} = SortedParticleList{N, M, T}
SortedParticleListM (alias for SortedParticleList{N, M, T} where {M, T, N})

julia> SortedParticleListM{1}
SortedParticleListM{1} (alias for SortedParticleList{N, 1, T} where {T, N})

```
