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


#1

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.


#2

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.


#3

Maybe of historical interest: 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.


#4

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 https://github.com/traktofon/ComputedArrays.jl/blob/for07/src/ComputedArrays.jl#L28.


#5

What about

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