OCaml Features



#let square (x) = x * x;;
square : int -> int = <fun>
#let rec fact (x) =
  if x <= 1 then 1 else x * fact (x - 1);;
fact : int -> int = <fun>
#let compose f g = function x -> f (g (x));;
compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
#let square_o_fact = compose square fact;;
square_o_fact : int -> int = <fun>
#square_o_fact 5;;
- : int = 14400



Objective Caml is a functional language. Functions (procedures) are first-class, ie, they can be passed as arguments to other functions or returned as the result of a function call.

Evaluation is applicative. Caml evaluates expressions greedily, as opposed to lazily. However, first-order value functions allows the manipulation of delayed expressions, and thus lazy evaluation of potentially infinite data structures is still possible.


Prev | Next