Enforcing function signatures by both argument & return types

I would love to see this too! Some previous discussion https://github.com/JuliaLang/julia/issues/17168 and Function Parameter Speculation #17168.

There’s a few challenges, the biggest of which is related to multiple dispatch–what happens if foo has multiple methods? (x::Int, y::Int) -> 1 + x + y and f(x::Int, y::Int) = 1 + x + y currently have different types in Julia. In fact, currently, a = (x, y) -> 1+x+y; b = (x, y) -> 1+x+y; typeof(a)==typeof(b) returns false. So there are many needed changes to the type system, including a return type foo(x::Int) --> Int

1 Like