I would like to dispatch a method like this, where T
gets the type <: AbstractParticles
and the type parameters end up in F
and NT
.
function Base.union(p1::T{F,NT},p2::S{F,NS}) where T <: AbstractParticles where S <: AbstractParticles{F,NS} where F where NT where NS
T{F,NT+NS}([p1.particles; p2.particles])
end
This does not work and an error
TypeError: in Type{...} expression, expected UnionAll, got TypeVar
occurs. The following definition is accepted, but it makes T
include the type parameters T{F,NT}
which I do not want.
function Base.union(p1::T,p2::S) where T <: AbstractParticles{F,NT} where S <: AbstractParticles{F,NS} where F where NT where NS
@show T
end
julia> union(p,p)
#T = Particles{Float64,1000}
Is there another way to express the former, or to strip Particles{Float64,1000}
from the type parameters without using eval
?
Edit:
The following works, but feels like a hack
function Base.union(p1::T,p2::S) where T <: AbstractParticles{F,NT} where S <: AbstractParticles{F,NS} where F where NT where NS
T.name.wrapper{F,NT+NS}([p1.particles; p2.particles])
end
It does not feel like I’m supposed to use the T.name.wrapper
Edit 2:
I can also put the function definition in a loop over the different possible T
and @eval
the function into existence.