I’ve tried to do the following
construct_instance{T}(::Type{T}) = T()
construct_instance{T<:Tuple}(::Type{T}) = tuple([construct_instance(t) for t in
T.parameters]...)
as a way to dynamically and recursively create an instance of a tuple type.
The tuple type might be nested, it might be any length > 0, and all
(supported) non-tuple types in the hierarchy are leaf-types with an empty
constructor defined.
This works insofar as it gives me the tuple I want back, but it’s not type
stable; the inferred return type is Tuple rather than T. I also tried
wrapping it in convert(T, tuple(...)), but that only gave me e.g. Tuple{Any,
Any} for a two-tuple type, which I assume is because type info is lost in
the list comprehension.
Is there a way to help type inference realize that it will get a T back,
even when T is a tuple type?
// T