An object which is Tuple, but not an NTuple{N, Any}

In Julia, is it possible to have an object, which is a Tuple, but not an NTuple{N, Any}?
I am thinking about this because, in the Iterators module, there are different method dispatches for NTuple and Tuple object for the function flatten_iteratorsize.

From what I understand, NTuple{N, Any} and Tuple are just aliases. Am I correct?

while

julia> (NTuple{N,Any} where N) == Tuple
true

what you are seeing for flatten_iteratorsize is dispatching on types, where the distinction of having a Tuple type (which can have any length) or an NTuple with a given length (which is used) is meaningful.

That’s true, but doesn’t taking length N as a generic parameter in the method make NTuple{N, Any} type same as Tuple?
I am not able to think of an example where the method with the NTuple dispatch will not be called (i.e. the one with Tuple dispatch be called). Can you please give such an example?

foo(::Type{<:Tuple}) = "I am some generic tuple type"
foo(::Type{<:NTuple{N,Any}}) where N = "I know my length, and it is $N"
foo(Tuple)              # will call first method
foo(Tuple{Int,Float64}) # will call second method
2 Likes