# How to write the type signature of a tuple of types?

**URL:** <https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 29, 2019, 5:11am UTC](https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492 "2019-03-29T05:11:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [March 29, 2019, 5:11am UTC](https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492/1 "2019-03-29T05:11:56Z")

</div>

For example, I have a type

```julia
abstract type Axis{a,A} end

```

How can I express in function type signature that I have a tuple of unknown numbers of `Axis` with different type parameters? For instance,

```julia
julia> Tuple{Axis{a,A}, Axis{b,B}} where {a,b,A,B}
Tuple{Axis{a,A},Axis{b,B}} where B where A where b where a

julia> Tuple{Axis{a,A}, Axis{b,B}, Axis{c,C}} where {a,b,A,B,c,C}
Tuple{Axis{a,A},Axis{b,B},Axis{c,C}} where C where c where B where A where b where a

```

How can I express them in a general unified type? I tried as follows but failed.

```julia
julia> Tuple{Axis...}
ERROR: MethodError: no method matching iterate(::Type{Axis})
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:589
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:589
  iterate(::ExponentialBackOff) at error.jl:171
  ...
Stacktrace:
 [1] append_any(::Tuple{DataType}, ::Vararg{Any,N} where N) at ./essentials.jl:426
 [2] top-level scope at none:0

```

In Python I can have

```python
from typing import Tuple
# To specify a variable-length tuple of homogeneous type, use literal ellipsis, e.g. 
Tuple[int, ...]

```

which is very handy. I want something similar in Julia.

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [March 29, 2019, 6:45am UTC](https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492/2 "2019-03-29T06:45:46Z")

</div>

Try the special `Vararg` type:

```julia
julia> ("a",) isa Tuple{String, Vararg{Int}}
true

julia> ("a",1,1,1) isa Tuple{String, Vararg{Int}}
true

```

---

<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:** [March 29, 2019, 6:46am UTC](https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492/3 "2019-03-29T06:46:09Z")

</div>

I think you are looking for `NTuple{Axis,2}` etc. Also look at `Vararg`. Search the manual and you will find examples.

---

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [March 29, 2019, 6:59am UTC](https://discourse.julialang.org/t/how-to-write-the-type-signature-of-a-tuple-of-types/22492/4 "2019-03-29T06:59:19Z")

</div>

Thanks, just to point out that

```julia
NTuple{N, T}

  A compact way of representing the type for a tuple of length N where all elements are
  of type T.

```

I found that I could write `NTuple{N, T} where N` to solve this. I did not think about using `NTuple` was because I thought first I need to specify `N`, which is not known. And also, a `UnionAll` type does allow me to have different parameterized `Axis`s:

```julia
julia> struct B{a, A} <: Axis{a, A}
           data::A
       end

julia> B{a}(data::A) where {a, A} = B{a, A}(data)

julia> (B{:s}(rand(3)), B{:q}([1,2,4,5])) isa NTuple{N, Axis} where N
true

```
