# Getting the return type of a function call without actually running it

**URL:** <https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515>\
**Category:** General Usage\
**Created:** [July 19, 2018, 9:59pm UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515 "2018-07-19T21:59:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [July 19, 2018, 9:59pm UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515/1 "2018-07-19T21:59:26Z")

</div>

Hi fellows,

I am working on a way to dispatch according to the return type of a function call.

I asked a similar question here:

> [@How to calculate the typeof an expression without actually running it?](https://discourse.julialang.org/t/how-to-calculate-the-typeof-an-expression-without-actually-running-it/7211):
>
> Hi, I would like to calculate the typeof an expression without running it. For example: function f(x::Int) y = x+3 if x \> 0 y+=1 else y-=3 end x+y end for example in a macro i am working with the expressions of this function and is there a way to calculate y+=1 to be type of Int? Thanks

I am asking it again in case something in julia may have changed.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [July 19, 2018, 10:50pm UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515/2 "2018-07-19T22:50:49Z")

</div>

Nothing fundamental, no. It’s still impossible to do in general. Can you explain more about what you’re actually trying to accomplish? Perhaps then we can be more helpful.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [July 20, 2018, 5:53am UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515/3 "2018-07-20T05:53:22Z")

</div>

> [@Qiyamah](#):
>
> I am working on a way to dispatch according to the return type of a function call.

Maybe of historical interest: [GitHub - mauro3/Traits.jl: Exploration of traits in Julia](https://github.com/mauro3/Traits.jl). This package was able to do this, but does not work anymore due to more stringent restrictions on generated functions.

---

<div class="post-metadata">

**Author:** ![traktofon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/traktofon/32/591_2.png) [@traktofon](https://discourse.julialang.org/u/traktofon)\
**Post date:** [July 20, 2018, 11:31am UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515/4 "2018-07-20T11:31:36Z")

</div>

As others have said, it’s impossible to do in general, but faced with a similar problem in my (unregistered) package [ComputedArrays.jl](https://github.com/traktofon/ComputedArrays.jl/tree/for07) I am using the following (in julia v0.7):

```julia
T = Union{Base.return_types(fn, argtypes)...}

```

where `argtypes` is a tuple with the types of the arguments to the function `fn`. See [ComputedArrays.jl/ComputedArrays.jl at for07 · traktofon/ComputedArrays.jl · GitHub](https://github.com/traktofon/ComputedArrays.jl/blob/for07/src/ComputedArrays.jl#L28).

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [July 20, 2018, 11:41am UTC](https://discourse.julialang.org/t/getting-the-return-type-of-a-function-call-without-actually-running-it/12515/5 "2018-07-20T11:41:31Z")

</div>

What about

```julia
f(x) = x
Base.return_types(f, (Int64,))

```
