# User Defined N-ary Types, like Array{T,N}?

**URL:** <https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239>\
**Category:** General Usage\
**Tags:** type, parametric-types\
**Created:** [November 22, 2017, 3:00am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239 "2017-11-22T03:00:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [November 22, 2017, 3:00am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/1 "2017-11-22T03:00:45Z")

</div>

Is it possible for users to define types with a parametric integer value? Similar to the Array{T,1}, Array{T,2}, Array{T,3}… types?

On a related note, It is possible or users to define types similar to Tuples, which have a variable number of type parameters?

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [November 22, 2017, 3:07am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/2 "2017-11-22T03:07:58Z")

</div>

You can actually do that for any `isbits` type.

```julia
julia> struct test{T} end

julia> a = test{3}()
test{3}()

julia> b = test{(1,2,3,4)}()
test{(1, 2, 3, 4)}()

julia> using StaticArrays

julia> arr = @SArray [1. 2.; 3. 4.]
2×2 StaticArrays.SArray{Tuple{2,2},Float64,2,4}:
 1.0 2.0
 3.0 4.0

julia> c = test{arr}()
test{[1.0 2.0; 3.0 4.0]}()

julia> d = test{:mySymbol}()
test{:mySymbol}()

```

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [November 22, 2017, 3:10am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/3 "2017-11-22T03:10:24Z")

</div>

Well, I just noticed that `isbits` of a `Symbol` returns `false`, but you can use it as type parameter nevertheless 🤔

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 22, 2017, 7:22am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/4 "2017-11-22T07:22:33Z")

</div>

Symbol is the only exception as far as I know.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 22, 2017, 9:22am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/5 "2017-11-22T09:22:46Z")

</div>

I asked a similar question here, you may find the answers useful:

> [@What are valid type parameters?](https://discourse.julialang.org/t/what-are-valid-type-parameters/471):
>
> I am trying to stuff quite a bit of information into parameters of a type, in the hope that dispatching on this will create efficient code. Doing this, I ran into the question of what is allowed, exactly. Is the following correct: a value V is valid for a type parameter iff either isbits(V) isa(V, Symbol) isa(V, Type) Is there anything else? To make things concrete, what I am trying to encode as type parameters are a return type, and a Vector{Pair{Int,Type}}. The latter does not work, but …

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [November 23, 2017, 1:47am UTC](https://discourse.julialang.org/t/user-defined-n-ary-types-like-array-t-n/7239/6 "2017-11-23T01:47:01Z")

</div>

Super helpful. Thanks!
