# List of elements with unknown type, is it bad?

**URL:** <https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 25, 2021, 9:44am UTC](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893 "2021-01-25T09:44:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [January 25, 2021, 12:55pm UTC](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893/2 "2021-01-25T12:55:20Z")

</div>

> [@rveltz](#):
>
> Surprisingly to me, using `@code_warntype` does not reveal type unstability.

If I understand correctly you did something like `@code_warntype foo(1.2)`, right? Well, this by itself is not type-unstable. The returned value is always a `Vector{Any}` (that is a concrete type), so the “_function itself_” is type-stable. What is type-unstable is dealing with values obtained _from_ the `Vector`:

```julia
julia> a = foo(1.2);
julia> @code_warntype a[rand(1:15)]
Variables
  #self#::Core.Compiler.Const(getindex, false)
  A::Array{Any,1}
  i1::Int64

Body::Any
1 ─ %1 = Base.arrayref($(Expr(:boundscheck)), A, i1)::Any
└── return %1

```

Because then, the type returned is `Any` (not `Vector{Any}`) and `Any` is the root abstract type, so this can be anything.

If you really need a dynamic number of elements of distinct type, there is not much else to do. If every element is a subtype of `ABS` then I would suggest changing the function first line to `res = Vector{ABS}(undef, 0)` to at least restrict the type a little. Accessing elements will be type unstable anyway (because `ABS` is an abstract type) but maybe the compiler can optimize one or other thing.

I suggest you look at [this recent answer of mine](https://discourse.julialang.org/t/type-stability-problem-vcat-tuple-and-function/53862/5) about how to limit the damage cause by type-instability.

---

_[View the full topic](https://discourse.julialang.org/t/list-of-elements-with-unknown-type-is-it-bad/53893)._
