# Composite Types of Arrays

**URL:** <https://discourse.julialang.org/t/composite-types-of-arrays/11110>\
**Category:** Performance\
**Created:** [May 23, 2018, 8:22pm UTC](https://discourse.julialang.org/t/composite-types-of-arrays/11110 "2018-05-23T20:22:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [May 23, 2018, 8:22pm UTC](https://discourse.julialang.org/t/composite-types-of-arrays/11110/1 "2018-05-23T20:22:45Z")

</div>

I would like to do something like:

```julia
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:

```julia
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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 23, 2018, 8:31pm UTC](https://discourse.julialang.org/t/composite-types-of-arrays/11110/2 "2018-05-23T20:31:00Z")

</div>

> [@Juser](#):
>
> Alternatively, I could use:
> 
> ```julia
> struct Vecs{T}
> A::T
> B::T
> end
> 
> ```

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

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

```

---

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [May 26, 2018, 8:09pm UTC](https://discourse.julialang.org/t/composite-types-of-arrays/11110/3 "2018-05-26T20:09:08Z")

</div>

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:

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

```
