Why does `NTuple{N, T}`'s parameter order is not `{T, N}`?

tuple
syntax
design

#1

Consider AbstractArray{T,N} or Vararg{T,N}, whose orders are both {T, N}. So why do NTuple has a different order?


#2

You can have both, if you do like StaticArrays and define const TupleN{T,N} = NTuple{N,T}.


#3

Thanks @Per, I just want to know under what consideration made the developers choose this syntax?


#4

Yeah, I’m curious too. {T,N} feels more natural.


#5

The way to remember this is that the N comes first in NTuple. It’s just a convenience definition for Tuple{Vararg{T, N}}


#6

Thank you @Keno, for me, keeping the consistent order is easier to remember.


#7

I like the chosen order, because it allows me to specify only N (as in f(t::NTuple{N}) where N = ...), which for an NTuple I happen to need more often than the type (to know and use the number of elements statically). But as said above, this is just a convenient alias. Define another if you need it, that’s the beauty of this.