Edit: Initial question was simple to answer due to a typo in the code, so I updated the question to make it a bit more exotic
Alias types for different views of tuples
How to define an alias type for a tuple with any of the following combination of features:
- fixed size vs. arbitrary size
- elements of a fixed type (say Int64} vs. qualifying the type of the element to be a parameter of the alias type
Here is my attempt. Given the following hint
julia> typeof((1,2,3,4))
NTuple{4, Int64}
I could define an alias type for a fixed size fixed type tuple as follows:
julia> const Tuple4DInt64 = NTuple{4,Int64}
If the type of the elements need to be qualified, then the above code can be modified to
julia> Tuple4D = NTuple{4,T} where T
This is equivalent to
julia> Tuple4D = NTuple{4,T} where T <: Any
which can be used as follows:
julia> Tuple4D
NTuple{4, T} where T
julia> Tuple4D{Int64}
NTuple{4, Int64}
One can ensure the alias type to be a tuple of fixed size but with various arbitrary types of elements as follows
julia> Tuple4D{Any}
NTuple{4, Any}
Qualifying the size of the tuple as a parameter for the type alias is intuitive as well:
julia> TupleNDInt64 = NTuple{N,Int64} where N
Tuple{Vararg{Int64, N}}
julia> TupleNDInt64{4}
NTupleNDInt64{4, Int64}
Last case, qualifying both the type and the size as parameters for the alias type, here I am not able to get it right.