AnatomyOf

Anatomy of an OCaml file

example.ml
1(* A minimal OCaml file -- no semicolons were harmed, well, maybe a few *)
2open Printf
3
4type greeting = { text: string; volume: int }
5
6let shout g = String.uppercase_ascii g.text ^ String.make g.volume '!'
7
8let () =
9 let g = { text = "hello"; volume = 3 } in
10 printf "%s\n" (shout g) (* the type checker slept fine, so it must be correct *)
OCaml is a general-purpose, industrial-strength functional programming language with a strong static type system and type inference.