Composite Types of Arrays

I would like to do something like:

type Vecs{V,T}
      A::V{T}
      B::V{T}
end

where V could be Vector or SharedVector or some other specified AbstractVector and T is some sort of bits-type. I understand that I could type this in the following way:

type Vecs{T}
      A::AbstractVector{T}
      B::AbstractVector{T}
end

However, I suspect that this loses some efficiency by specifying only AbstractVector rather than SharedVector or Vector.

Alternatively, I could use:

type Vecs{T}
      A::T
      B::T
end

where T could take on things like Vector{Int64} or SharedVector{Float64}, etc., however this seems extremely inelegant.

Any suggestions? Is there something obvious I’m missing? Thank you!

This looks elegant to me! Another option, if you want the array type as well as their element type as parameters you can use

struct Vect{T,V<:AbstractArray{T}}
    A::V
    B::V
end
5 Likes

Thank you for your suggestion! I have implemented your suggested solution. Though verbose, it seems superior to either of the methods I proposed. Still, it would have been nice if syntax like the following worked, as it would lead to (what I feel to be) more intuitive code:

struct Vect{T,V<:AbstractArray}
    A::V{T}
    B::V{T}
end