You could qualify S and T so that the compiler knows they aren’t Vector and Dict, but are instead subtypes of some custom type of your own. In general, the translation T([getfield(x,f) for f in 1:nfields(T)]...) is not guaranteed to return the same object / value for all types anyways.
On Mon, May 4, 2015 at 7:47 AM Tamas Papp [email protected] <http://mailto:[email protected]> wrote: Hi, > > I wrote a function to map contents of composite types to vectors and > dictionaries: > > repack{S}(v::Vector, ::Type{S}) = S(v...) > repack{S}(d::Dict, ::Type{S}) = S([get(error,d,f) for f in > fieldnames(S)]...) > repack{S,T}(x::S, ::Type{Vector{T}}) = T[getfield(x,f) for f in > fieldnames(S)] > repack{S}(x::S, ::Type{Dict}) = [f => getfield(x,f) for f in fieldnames(S)] > > A minor problem is that methods are ambigous (in practice, this does > not cause any errors though). > > Is defining methods for each of the intersections the only way to > resolve this, or is there some alternative? If I could only dispatch on > a type being a composite type... Using v"0.4.0-dev+4616". > > Best, > > Tamas >
