Closures and Evaluation of Function Application, Order of Evaluation in OCaml
Functions with more than one argument
let add_three x + y + z = x + y + z;;
# val add_three : int -> int -> int -> int = <fun>
let t = add_three 6 3 2;;
# val t : int = 11
let add_three =
# fun x -> (fun y -> (fun z -> x + y + z));;
val add_three : int -> int -> int -> int = <fun>
- What is the value of add_three?
-
- Remeber:
let h = add_three 5 4;;
val h : int -> int = <fun>
3;;
h int = 12
- : 7;;
h int = 16 - :
Partial application also called sectioning
Functions as argumentslet thrice f x = f(f(f x));;
# val thrice : ('a -> 'a) -> ('a -> 'a) = <fun>
let g = thrice plus_two;;
# val g : int -> int = <fun>
4;;
# g int = 10
- : fun s -> "Hi!" ^ s) "Good-bye!";;
# thrice (string = "Hi! Hi! Hi! Good-bye!" - :