Note that this has been discussed many times already, e.g.:
- julia issue #210: function types
- Want a field signature more specific than 'Function'
- Function Parameter Speculation #17168
- Function type specification
- Ability to define function templates
- Higher-order function argument types
- Enforcing function signatures by both argument & return types
- Proposal to make functions first class citizens in context of multiple dispatch
- How to type annotate functions which take functions as args
Actually implementing it in a way that is compatible with Julia’s multiple dispatch is quite tricky. This is the only start at an attempt that I know of: julia#10269: Towards typed lambdas.
For example, it makes runtime behavior / dispatch (whether a particular function f
is accepted as an argument of another function) potentially dependent on type inference of f
, which is problematic in a dynamic language like Julia where type inference is not required to succeed — it’s only an optimization. (Unlike static languages like Rust or Haskell.)