# Resumable function as a struct field var...error: "struct" expression not at top level

**URL:** <https://discourse.julialang.org/t/resumable-function-as-a-struct-field-var-error-struct-expression-not-at-top-level/98730>\
**Category:** New to Julia\
**Created:** [May 12, 2023, 10:08am UTC](https://discourse.julialang.org/t/resumable-function-as-a-struct-field-var-error-struct-expression-not-at-top-level/98730 "2023-05-12T10:08:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mongi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mongi/32/43334_2.png) [@mongi](https://discourse.julialang.org/u/mongi)\
**Post date:** [May 12, 2023, 10:08am UTC](https://discourse.julialang.org/t/resumable-function-as-a-struct-field-var-error-struct-expression-not-at-top-level/98730/1 "2023-05-12T10:08:43Z")

</div>

Greetings,  
A resumable function (singleton type of function , subtype of Function) , when put as a struct field variable, causes the error “struct expression not at top level” while a normal function does not. Could anyone explain? thanks

```julia
using ResumableFunctions
struct foo
    f::Function
end
function test()
    @resumable function f(i::Int)
        if i==1
            @yield 1
        else
            @yield 2
        end
    end
    odepro=foo(f)
end

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [May 12, 2023, 10:27am UTC](https://discourse.julialang.org/t/resumable-function-as-a-struct-field-var-error-struct-expression-not-at-top-level/98730/2 "2023-05-12T10:27:24Z")

</div>

`@resumable` transforms the `function` block to a larger expression that includes a `mutable struct` block. `struct` blocks can only be defined in the global scope, like where `struct foo` is. The error is thrown before `foo(f)` even runs, `foo`’s field is not the cause of the issue.
