# Output type from input function handle output type?

**URL:** <https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373>\
**Category:** General Usage\
**Created:** [November 16, 2022, 11:27pm UTC](https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373 "2022-11-16T23:27:45Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)\
**Post date:** [November 17, 2022, 4:45pm UTC](https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373/13 "2022-11-17T16:45:11Z")

</div>

I see. Here’s the recursive function:

```julia
function valuedispatch(::Val{lower}, ::Val{upper}, fun, val) where {lower, upper}
    if lower >= upper
        return fun(Val(upper))
    end
    midpoint::Int = lower + div(upper - lower, 2)
    if val <= midpoint
        return valuedispatch(Val(lower), Val(midpoint), fun, val)
    else
        return valuedispatch(Val(midpoint+1), Val(upper), fun, val)
    end
end

```

But actually, I no longer think this approach will be any better than generating a single (non-recursive) function, using [the approach here](https://discourse.julialang.org/t/experiments-in-speeding-up-runtime-dispatch-for-integer-value-specialization/90355/6).

---

_[View the full topic](https://discourse.julialang.org/t/output-type-from-input-function-handle-output-type/90373)._
