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

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:

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

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.

1 Like

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

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

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.

What about

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