The types are the same, but the function signature is different. Why is the type different?
The types do not really match.
When you write:
let addition1 ab = a + b
You create a function that is different from
let addition2 (a, b) = a + b
In the second case, the brackets and comma create a tuple , which means that your function takes a single parameter, which is a tuple (typed as int * int ) and returns int .
The first case creates a function that can be specified. A typical signature int -> int -> int means that it creates a function that takes int, and then returns a function that accepts int and returns int. This allows you to use a partial application:
let partially_applied_addition1 = addition1 3
See functions in white papers and Currying from fsharpforfunandprofit for details .
Currying permission is much more common in F # code. In the general case, the use of tuples as a parameter is mainly performed for scenarios of interaction with libraries of the base class or when planning the API to be used with C # or other languages. The possibility of partial application thus allows you to work as a pipeline:
let answer = getSomeIntegerValue () |> addition1 12
The above form will not compile with the above, since it cannot work with a partial application.
source share