Make an existing type a child of an abstract type

No. But you can wrap it and type the wrapper.

Heres a toy example, AbstractVector3D should actualy be <: AbstractArray{T,N}:

abstract type Vector3D <: AbstracVector3D
    data::SVector{3}
end

Base.parent(a::Vector3D) = a.data

Then you can write out all the SVector methods you need manually like:

getindex(a::Vector3D, I...) = getindex(parent(a), I...)

Or use the @forward macro in Lazy.jl to do them all at once. I can’t recall exactly what you need here.

But first you should have a good reason why you need such specialized types.

2 Likes