Higher-order function argument types

question

#1

When I use a function as an argument, is there type information available that includes its domain and range?

It would be great to be able to do something like this:

function Nullable(f :: Function{X,Y}) 
    nx -> begin
        if isnull(nx)
            return Nullable{Y}()
        else
            y = f(unsafe_get(x))
            return Nullable(y)
        end
    end
end

But the type information for functions in Julia is different than this, and doesn’t yet make sense to me. Is something like this possible, without hand-coding all of the types? Or does Julia even represent function types in a way I can extract this kind of information?

Thanks!


#2

It’s even more difficult than that. Functions in Julia don’t truly have arguments, only methods do. What you’re really looking for is a way to grab a method that has a specific signature, or ask if a function can have a given signature.


#3

You may find these related discussions useful. They have pointers to discussions in issues, and other discussions on this forum, and previously Google groups, etc.





#4

See also

https://github.com/JuliaLang/julia/pull/10269

https://github.com/JuliaLang/julia/issues/19206