let x = 3 let y = 4 let () = Printf.printf "%d + %d = %d\n" x y (x + y) let add x y = x + y let rec fact n = if n = 1 then 1 else n * fact (n - 1) add x y (add x) y let add_five = add 5 let six = add_five 1 let hi x = printf "Hi, %s!\n" x let hi = printf "Hi, %s!\n" List.iter (Printf.printf "- %s\n") ["foo"; "bar"] let (|>) x f = f x ["foo"; "bar"] |> List.map String.uppercase |> List.iter (Printf.printf "- %s\n") let to_string x = match x with | 1 -> "one" | 2 -> "two" | n -> string_of_int n let to_string = function | 1 -> "one" | 2 -> "two" | n -> string_of_int n type download_result = | Success of filepath | Network_error of string | Aborted_by_user match download url with | Success file -> process file | Network_error msg -> alert msg | Aborted_by_user -> () type program = { name : string; homepage : url option; } type 'a result = | Success of 'a | Error of exn let success = function | Success value -> value | Error ex -> raise ex let () = match ask "Automatic?" with | `yes -> automatic () | `no -> manual () ocaml prog.ml ocamlbuild prog.native true: warn(A), strict_sequence opam install lablgtk package(lablgtk2, lablgtk2.auto-init) ocamlbuild -use-ocamlfind type stock_item = { id : stock_id; mutable location : position; } let total = ref 0 in for i = 1 to 10 do total := !total + i done; Printf.printf "Total = %d\n" !total ocamlbuild -use-ocamlfind db.inferred.mli