Reputation: 33
What is the difference between these two functions?
let increment1 x = x +1 // (int -> 'a) -> 'a // why??
let increment2 x = x + 1 // int -> int // this is clear
Upvotes: 3
Views: 53
Reputation: 80734
The lack of space between +
and 1
changes the meaning. When there is a space, it reads as operator +
applied to argument 1
, but without a space it means "positive one", similarly to how -1
means "negative one".
And since +1
is a number of type int
, then x +1
must be a function application, applying function x
to the argument +1
, and therefore x
must be of type int -> 'a
for some generic type 'a
Upvotes: 4