When I was learning OCaml essentials, I was told that every function in OCaml is actually a function with only one parameter. A multi-argument function is actually a functio
Okay, I learned that the native compiler will optimize your code, what I expect it to do. But here is the bytecode compiler:
let plus1 x y = x + y
let plus2 = fun x y -> x + y
let plus3 = function x -> function y -> x + y
treated with ocamlc -c -dinstr temp.ml
gives me:
branch L4
restart
L1: grab 1
acc 1
push
acc 1
addint
return 2
restart
L2: grab 1
acc 1
push
acc 1
addint
return 2
restart
L3: grab 1
acc 1
push
acc 1
addint
return 2
which means the result is exactly the same, it is only a syntax difference. And the arguments are taken one by one.
Btw, one more syntax point: fun
can be written with n arguments, function
only with one.
From the conceptual point of view I would largely favor function x -> function y ->
over the others.