Function inside struct allocates when referenced

So in concrete terms, this is what a more efficient Box would look like:

struct Box{F}
    func::F
end

No need to specify F <: Function, since there are objects that are not functions but still callable.

However, this trick will not work well for func_array. Indeed, each function f in Julia has its own type typeof(f), and so you cannot specify a concrete type for the array elements unless all of its elements have the same type, i.e. they are the same function. Which would make said array useless.
Why do you need an array of functions in your use case?

5 Likes