Function application is written just by putting functions next to each other
e0 e1 ... en, where e0 is the function expression, and e1 through en are the parameters. Note that there are no commas or parenthesis, it's incorrect to add them.
Evaluation is done by first evaluating all of the sub-expressions (e1 through en) then evaluating the function.
e0 => v0, ..., en => vn where v0 ... vn are functions with signature fun x1 ... xn -> e vi for xi yielding the new expression e'. Evaluate it e' ==> vv.Let's try it with the function fun x -> x + 1
(fun x -> x + 1) (2 + 3);;
- : int = 6
What's happening here?
e0 is evaluated to a value - done because the anonymous function is a value.e1 is evaluated to a value - 2 + 3 ==> 5. Now we have (fun x -> x + 1) 5;;.5 + 1.5 + 1 ==> 6.Now let's try another example:
(fun x y -> x + y) (3 * 1) (3 - 1);;
- : int = 5
e0 is evaluated to a value – done because the anonymous function is a value.e1 and e2 are evaluated to values3 * 1 ==> 33 - 1 ==> 23 + 23 + 2 ==> 5