# Type instability possibly due to variable playing role of input and output

**URL:** <https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178>\
**Category:** General Usage\
**Tags:** question, tuple, code\_warntype, type-stability\
**Created:** [February 13, 2024, 10:58pm UTC](https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178 "2024-02-13T22:58:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Nikos\_Gianniotis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nikos_gianniotis/32/11487_2.png) [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Post date:** [February 14, 2024, 1:16pm UTC](https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178/5 "2024-02-14T13:16:40Z")

</div>

After further experimentation, I figured out that my problem lies elsewhere. In particular, it has to do with how I use the `struct layer`. I have created the following MWE that demonstrates the issue I am facing:

```julia
struct example{F}
    
    f::F

end

function (e::example)(x)

    e.f(x)

end

function (V::Vector{example})(x)

    out = x

    for v in V

        out = v(out)

    end

    out

end

```

Let’s put this to work via the following:

```julia
V = [example(cos); example(sin)]

V(1.0) # try whether this works - yes it does

@code_warntype V(1.0) # check type stability - it fails!

```

Please help me understand why there is a type instability when calling `V(1.0)`. I believe I am facing the same issue in my simple neural network code.

I suspect the issue has to do with me instantiating a `Vector{example}` type when I create `V`.

---

_[View the full topic](https://discourse.julialang.org/t/type-instability-possibly-due-to-variable-playing-role-of-input-and-output/110178)._
