Say I want to have a type that looks something like
struct MyVectorType{T} <: AbstractVector{T}
pointer::Ptr{T}
length::Int
end
but I also want MyVectorType
to be a subtype of MyOtherAbstractTypeForDispatch
...
Can this be done? I haven't seemed to be able to make it work yet
It cannot, see https://github.com/JuliaLang/julia/issues/5
To achieve the desired behavior for dispatch you would need to use traits. Sadly there's no way to achieve this behavior ad-hoc if the functions to dispatch to weren't implemented with traits in mind.
One possibility may be to define another type which subtypes MyOtherAbstractTypeForDispatch
and have conversion methods between MyVectorType
and the new subtype so that you can convert back and forth depending on what dispatch behavior you want to achieve.
Typing in Julia makes a tree.
And there are always (AFAIK) one and only one direct supertype of a type.
So, I don't think what you're trying to do is possible.
You can use Union though, if you don't mind a bit of unstability for your pointer.
Brenhin Keller has marked this topic as resolved.
Thanks!
Last updated: Nov 06 2024 at 04:40 UTC