Introduction to the Objective Caml Programming Language
This document is an introduction to ML programming, specifically for the Objective Caml (OCaml) programming language from INRIA. OCaml is a dialect of the ML (Meta-Language) family of languages, which derive from the Classic ML language designed by Robin Milner in 1975 for the LCF (Logic of Computable Functions) theorem prover.
OCaml shares many features with other dialects of ML, and it provides several new features of its own. Throughout this document, we use the term ML to stand for any of the dialects of ML, and OCaml when a feature is specific to OCaml.
ML is a functional language, meaning that functions are treated as first-class values. Functions may be nested, functions may be passed as arguments to other functions, and functions can be stored in data structures. Functions are treated like their mathematical counterparts as much as possible. Assignment statements that permanently change the value of certain expressions are permitted, but used much less frequently than in languages like C or Java.
- ML is strongly typed, meaning that the type of every variable and every expression in a program is determined at compile-time.
- ML uses type inference to infer types for the expressions in a program.
- The ML type system is polymorphic, meaning that it is possible to write programs that work for values of any type.
- ML implements a pattern matching mechanism that unifies case analysis and data destructors.
- ML includes an expressive module system that allows data structures to be specified and defined abstractly.
- OCaml is also the only widely-available ML implementation to include an object system.
- OCaml includes a compiler that supports separate compilation.
- All the languages in the ML family have a formal semantics.