# Issue with Array of user-defined type

**URL:** https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166
**Category:** General Usage
**Created:** [July 16, 2020, 7:17am UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166 "2020-07-16T07:17:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)
#### Post date: [July 16, 2020, 7:17am UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166/1 "2020-07-16T07:17:38Z")

</div>

Hello,

I would like to create a parametric struct `Basis` that holds a vector of a user-defined type `ParamFcn`. I define the functions `getindex` and `setindex!` for the struct `Basis` but the command `@warn_type` that the the type can not be inferred

Here is an example:

```julia
import Base: @propagate_inbounds

abstract type ParamFcn end

struct constant <:ParamFcn
end

struct linear <:ParamFcn
end

struct rbf <:ParamFcn
        μ::Float64
        σ::Float64
end

struct Basis{m}
    f::Array{ParamFcn,1}
    function Basis(f::Array{ParamFcn,1})
        return new{size(f,1)}(f)
    end
end

Base.size(B::Basis{m}) where {m} = m
@propagate_inbounds Base.getindex(B::Basis{m}, i::Int) where {m} = getindex(B.f,i)
@propagate_inbounds Base.setindex!(B::Basis{m}, v::ParamFcn, i::Int) where {m} = setindex!(B.f,v,i)

B = Basis([constant(); linear(); rbf(1.0, 1.0)])
@code_warntype B[2]

```

Variables  
#self#::Core.Compiler.Const(getindex, false)  
B::Basis{3}  
i::Int64

Body::ParamFcn  
1 ─ nothing  
│ %2 = Base.getproperty(B, :f)::Array{ParamFcn,1}  
│ %3 = Main.getindex(%2, i)::ParamFcn  
└── return %3

**The output ::ParamFcn is in red**

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [July 16, 2020, 7:27am UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166/2 "2020-07-16T07:27:56Z")

</div>

It’s just telling you that the eltype of your array is an abstract type, equivalent to this:

```julia
Real[1, 2.0, 3//1]
@code_warntype ans[2] # Body::Real

```

---

<div class="post-metadata">

### Author: ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)
#### Post date: [July 16, 2020, 7:32am UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166/3 "2020-07-16T07:32:41Z")

</div>

Is it going to influence the performance of the code?

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [July 16, 2020, 7:35am UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166/4 "2020-07-16T07:35:35Z")

</div>

Yes it might. Certainly computing with a large array of eltye `Real` will be slower than the same with concrete `Float64`.

---

<div class="post-metadata">

### Author: ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)
#### Post date: [July 16, 2020, 3:50pm UTC](https://discourse.julialang.org/t/issue-with-array-of-user-defined-type/43166/5 "2020-07-16T15:50:05Z")

</div>

How can I circumvent this issue. ParamFcn is an abstract type to store parameterized scalar functions.
