# Is it possible to define a type that takes a variable number of type parameters

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-define-a-type-that-takes-a-variable-number-of-type-parameters/33264>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 12, 2020, 9:20am UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-that-takes-a-variable-number-of-type-parameters/33264 "2020-01-12T09:20:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkroso](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkroso/32/220909_2.png) [@jkroso](https://discourse.julialang.org/u/jkroso)\
**Post date:** [January 12, 2020, 9:20am UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-that-takes-a-variable-number-of-type-parameters/33264/1 "2020-01-12T09:20:06Z")

</div>

AFAIK there are two types in Julia that can take a variable number of type parameters: `Union` and `Tuple` but they both seem to be defined in C. Are there any implemented in Julia or can it not be done?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [January 12, 2020, 12:49pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-that-takes-a-variable-number-of-type-parameters/33264/2 "2020-01-12T12:49:57Z")

</div>

No, there isn’t currently any way to implement something like this in native Julia, especially since Tuple and Union are also special in many other ways, like now type covariance and the way subtyping works work. If you want to have a custom struct with multiple fields, you can always just use a Tuple as a typed field in your struct and perhaps add a more convenient constructor using splatting.

---

<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:** [January 12, 2020, 6:39pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-type-that-takes-a-variable-number-of-type-parameters/33264/3 "2020-01-12T18:39:48Z")

</div>

For a real-life example of a type using a tuple of parameters, as @simeonschaub suggested, you can check out `SArray` from StaticArrays.jl:

```julia
julia> SVector{3, Int}
SArray{Tuple{3},Int64,1,3}

julia> SMatrix{3, 3, Int, 9}
SArray{Tuple{3,3},Int64,2,9}

```

where the first type parameter of `SArray` is a tuple of dimensions whose length is equal to the number of dimensions in the array.
