Helping julia with runtime dispatch/arrowtypes

question

#1

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?


Proposal for a first-class dispatch wrapper
#2

Before we finalized on a solution in Base.


#3

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


#4

Hopefully <20 chars limit.>