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

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

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

2 Likes

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

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

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

2 Likes

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

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.