Why is a union of tuples a vector?


#1

Is there a compelling reason that

 # NTuple{T} means NTuple{N,T} for any appropriate Ns
 union{T}(x::NTuple{T}, y::NTuple{T})::Vector{T}
 # instead of (pretending N3 is allowed)
 union{T}(x::NTuple{T}, y::NTuple{T})::NTuple{T}

and similarly for intersect?


#2

Possibly because it would not be type stable, because you wouldn’t know ahead of time how many items will be in the returned tuple.


#3

@tomlee is correct: you shouldn’t really be treating tuples as a general container like this. It’s handy to do some computations with them, but in general they belong more to the type domain than the value domain. If there is in principle, no way to predict how many values you have – as is the case for unions – then you should definitely not be using tuples.