Julia’s dispatch is something we all love, but I can’t figure out the syntax for the case of creating the signature of a function which takes another function as an arg.
_ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.0.0 (2018-08-08) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | julia> function f(x::Number) return x^2+1 end f (generic function with 1 method) julia> function g(x::Number) return sqrt(x-1) end g (generic function with 1 method) julia> f(2) 5 julia> g(5) 2.0 julia> function h(_f, x :: Number) return g(_f(x)) end h (generic function with 1 method) julia> h(f, 1) 1.0
If I wanted to annotate the function h’s arg _f, how would I do so? I was hoping for something like Haskell where you could say a->a (NB, I’m not a haskell programmer but I’m acquainted with the concepts). I suspect I don’t fully understand Julia’s type system when it comes to functions because if I try…
julia> typeof(h) typeof(h)
… I get output which to me seems unhelpful. While my code works without such an annotation, I hope making that explicit is supported syntax.
If you think you see the gap in my understanding and/or have resources explaining this part of the language I’d be very grateful!