I suspect what I want isn’t possible but wanted to ask here to be certain (or to learn precisely why it isn’t possible).
The setup for the question is as follows. Suppose I have a function:
function nested_ntuple(::Val{Ns}, ::Type{T}) where {Ns, T}
if length(Ns) == 1
return NTuple{first(Ns), T}
else
return NTuple{first(Ns), nested_ntuple(Val{Base.tail(Ns)}(), T)}
end
end
which generates nested NTuple types, such that e.g.
nested_ntuple(Val{(1,2)}(), String) === NTuple{1, NTuple{2, String}}
nested_ntuple(Val{(2,4,3)}(), Float64) === NTuple{2, NTuple{4, NTuple{3, Float64}}}
and so on.
What I’m then interested in is specifying a type with variably nested NTuple fields. I.e., conceptually, I’m looking for something like this:
struct A{Ns, T}
x::nested_ntuple(Ns, T)
end
(Of course, this isn’t a valid signature for specifying a type since we cannot use functions on the type parameters for specifying struct fields - but the point is just to say that it should assign a nested tuple type to x
).
As context, the reason I am interested in this was to play around with alternatives to e.g. StaticArrays’ use of one long “flat” NTuple for all array data - and the associated “dangling” type parameter L
- i.e., I wanted to see what the implications are of instead using a nested NTuple approach (in the spirit of https://github.com/JuliaLang/julia/issues/18466#issuecomment-274353910 - and motivated by that entire issue as well).