Programming style

The intent of this page is to give hints on how to write more elegant OCaml programs, from simple formatting issues to the choice between functional, imperative or object-oriented styles. This page has a discussion corner.

See also: Caml programming guidelines

Program formatting guidelines

The Caml programming guidelines is a very good guide for that.

When to "open" a module

Modules such as Printf which provide unique names (printf, fprintf, ...) usually deserve to be opened at the beginning of the file:

open Printf
...
printf "Hello %s\n" username

Some other modules which provides names like iter or map which are provided by many common modules (List, Array, ...) are usually not opened using an "open" directive:

List.iter print_endline some_list;
Array.iter do_something some_array;