# Helping julia with runtime dispatch/arrowtypes

**URL:** <https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 22, 2016, 3:14pm UTC](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104 "2016-12-22T15:14:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [December 22, 2016, 3:14pm UTC](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104/1 "2016-12-22T15:14:30Z")

</div>

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

```julia
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

```julia
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?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 22, 2016, 3:32pm UTC](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104/2 "2016-12-22T15:32:40Z")

</div>

[https://github.com/yuyichao/FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl)

Before we finalized on a solution in Base.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [December 22, 2016, 5:31pm UTC](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104/3 "2016-12-22T17:31:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 22, 2016, 6:10pm UTC](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104/4 "2016-12-22T18:10:43Z")

</div>

> [@jw3126](#):
>
> Julia 1.0?

Hopefully \<20 chars limit.\>
