It doesn’t go the whole way but for efficient code you probably want
struct A{T <: Function}
f::T
end
by parameterizing your struct the compiler can actually keep track of the specific intricies of the function f (including inferrring its return type automatically)
Taking a look at the test files might help. Here’s a little something to get you started:
using FunctionWrappers
import FunctionWrappers: FunctionWrapper
# A function that takes two Ts and returns a T.
struct ReturnCaptured{T}
fn::FunctionWrapper{T, Tuple{T,T}}
end
(f::ReturnCaptured{T})(x::T, y::T) where{T} = f.fn(x,y)
my_cool_function = ReturnCaptured{Float64}((x,y)->sqrt(abs2(x-y)))
my_cool_function(1.0, 2.0)