Hi,
Given the type of a NamedTuple
, I want to make operations on the types of the values (or fields) of the type, ultimately to compute a new type and allocate memory.
Here is a little code
function see(::Type{NT}) where{K,V,NT<:NamedTuple{K,V}}
@show K
@show V
get(V)
return
end
function see(::Type{V}) where{A,B,V<:Tuple{A,B}}
@show A,B
return
end
T = typeof((a=(1,2.),b=:hi))
see(T)
which displays
K = (:a, :b)
V = Tuple{Tuple{Int64, Float64}, Symbol}
(A, B) = (Tuple{Int64, Float64}, Symbol)
as wanted: A
, and B
contain the types of the values of a variable of type T
.
So far so good. The catch is, I want to be able to analyse the type T
of NamedTuple
s of arbitrary length. Nothing loath, I try
function see(::Type{V}) where{A...,V<:Tuple{A...}}
@show A...
return
end
but get the error
ERROR: syntax: invalid variable expression in "where"
around [the new method]
So slurping isn’t the thing in where
constructs. New attempt
function see(::Type{V}) where{A,V<:Tuple{A}}
@show A
return
end
where I again hope A
will be a Tuple
of Type
s.
ERROR: MethodError: no method matching
see(::Type{Tuple{Tuple{Int64, Float64}, Symbol}})
Closest candidates are: [...]
Any clever ideas?