What is the actual reason of having `->` before return type

I’d like to remark that the similarities to mathematical notation or Haskell are a bit more limited than the previous comments might suggest. In maths or Haskell you give function signatures independent from the defining equation.

mathematical:

𝑓: β„€ β†’ β„€
𝑓(π‘₯) = π‘₯Β² βˆ’ 1

Haskell:

f :: Integer -> Integer
f x = x^2 - 1

Rust (although i64 is not quite all integers):

fn f(x: i64) -> i64 { x.pow(2) - 1 }

for the record, there’s also (among even more other alternatives):
mathematical:

𝑓: β„€ β†’ β„€
π‘₯ ↦ π‘₯Β² βˆ’ 1

4 Likes