Helping julia with runtime dispatch/arrowtypes

I have a program in which there are states about which I need to check whether some predicates hold or not.

type State 
    ... 
end
immutable Predicate 
    f::Function 
end
(p::Predicate)(s::State)::Bool = p.f(s)

Now in my program I have a varying state and a varying list of predicates I need to check. Unfortunately calling a predicate on a state causes a runtime dispatch and hence is slow. Also I can’t do

immutable Predicate{F} 
    f::F 
end

since this causes a type instability since my predicate list varies. Is there a way to implement the above mechanic in a fast way? E.g. storing a pointer to the correct method in the Predicate type or something?

1 Like

https://github.com/yuyichao/FunctionWrappers.jl

Before we finalized on a solution in Base.

1 Like

Cool thanks! Do you think there will be a solution Julia 1.0?

Hopefully <20 chars limit.>