OCaml Language Overview handout #2
Data Type Example Operators/Functions
-------------------------------------------------------------------------------
integers int 42 + - * / mod abs
reals float 17.5 +. -. *. /. abs_float
booleans bool true && || not < > <= >= = <>
strings string "hello" ^ String.length String.sub s.[i]
characters char 'a'
lists list of t [17; 2; 5] List.hd List.tl List.length :: @
tuples t1 * t2... (12, "abc")
type conversion functions:
_of_ where and are int, float, string
float_of_int(42)
comments:
(* this is a comment *)
variable binding:
let =
let x = 2 + 3 * 5
conditional:
if then else
if x < y then x else y
simple function
let () =
let sum(a, b) = a + b
recursive function
let rec () =
let rec factorial(n) = if n = 0 then 1 else n * factorial(n - 1)