User Defined N-ary Types, like Array{T,N}?

Is it possible for users to define types with a parametric integer value? Similar to the Array{T,1}, Array{T,2}, Array{T,3}… types?

On a related note, It is possible or users to define types similar to Tuples, which have a variable number of type parameters?

You can actually do that for any isbits type.

julia> struct test{T} end

julia> a = test{3}()
test{3}()

julia> b = test{(1,2,3,4)}()
test{(1, 2, 3, 4)}()

julia> using StaticArrays

julia> arr = @SArray [1. 2.; 3. 4.]
2×2 StaticArrays.SArray{Tuple{2,2},Float64,2,4}:
 1.0  2.0
 3.0  4.0

julia> c = test{arr}()
test{[1.0 2.0; 3.0 4.0]}()

julia> d = test{:mySymbol}()
test{:mySymbol}()
1 Like

Well, I just noticed that isbits of a Symbol returns false, but you can use it as type parameter nevertheless :thinking:

Symbol is the only exception as far as I know.

I asked a similar question here, you may find the answers useful:

2 Likes

Super helpful. Thanks!