Your assumption is correct, in this case the functions exactly match.
You can see this by checking the generated IL code (as shown by Craig), and you can also see this by looking at the type output by the F # compiler. In both cases, you will see int -> int -> int . The F # language considers this as a function that takes an int and returns int -> int , but actually compiles as a method with several arguments (for efficiency).
If you write fun immediately after let .. = , then the compiler will turn this into a standard function. However, you can write code that is slightly different if you do some calculations before returning the function:
let f1 ab = printfn "hi"; a + b let f2 a = printfn "hi"; (fun b -> a + b)
Now the two functions are very different, because the second prints "hi" when you give it only one argument (and then returns a function that you can call):
> let f = f2 1;; hi // The body is called, prints val f : (int -> int) // and returns function > f 2;; // This runs the body of 'fun' val it : int = 3 // which performs the additiion
You can write the same code with f1 , but the first command will simply create a new function, and the second command will print βhelloβ and add.
In this case, the generated IL code for f2 will be different. This will be a function that returns a function (of type FSharpFunc<int, int> ). The type displayed by F # is also different: type int -> (int -> int) instead of int -> int -> int . You can use the values ββof these two types in exactly the same way, but this hints that the former may have some effects when you give it one argument.
Tomas petricek
source share