How to store functions in a structure in a proper way?

Hello and welcome to the community!

Try

struct Foo{F<:Function} 
    f::F
end

To make sure the field is concretely typed.

When the compiler cannot figure out the correct type at compile time you’ll typically see many additional allocations.

8 Likes