What is Caml ?

Contact the author Pierre.Weis@inria.fr

Created in January 1996.

Caml is a programming language, easy to learn, easy to use, and yet amazingly powerful.

It is developed and distributed by INRIA (the main French research institute for computer science), since 1984. It is freely available for Unix, PC or Macintosh.

There exist two flavors of Caml: Caml Light and Objective Caml. Caml Light is merely a subset of Objective Caml, especially designed for teaching and learning the art of programming.
In addition to the Caml Light's core language, Objective Caml features a powerful modules system, full support to object-oriented paradigm, and an optimizing compiler.

I give here a short overview of the language, that let you get an idea of the salient features of Caml.

The Caml programming examples that illustrate this text are in One hundred lines of Caml.


Caml is freely available, and highly portable, since it runs under virtually any Unix, PC, or Macintosh platform.

To obtain the free software CD-ROM, you must write to the following address:

INRIA - SICS Diffusion
Distribution de Caml Light
B.P. 105
78153 Le Chesnay CEDEX

send an envelope, appropriate for a CD-ROM, with your name and address, and an International Reply Coupon.


Caml is a safe language. The compiler performs many sanity checks on programs before compilation. That's why many programming errors cannot happen in Caml: data type confusions, erroneous accesses into compound values become just impossible. In effect, all these points are carefully verified by the compiler, so that the data accesses can be delegated to the compiler code generator, to ensure that data manipulated by programs may never be corrupted: the perfect integrity of data manipulated by programs is granted for free in Caml.

Caml is statically type-checked, but there is no need to add type informations in programs (as in Ada or Pascal, or C): type annotations are fully automatic and handled by the compiler.

Data Types

Numerous data types are predefined in Caml. This includes:

Beyond these powerful predefined types, Caml offers powerful means to defined new data types: records, enumerated types, and sum types. Sum types can be thought as a generalization of union data types, that is clean, powerful, and yet simple to understand. They allow unrestricted definitions of heterogeneous values, tagged by data constructors.

As desired, these types can be defined concretely (data constructors are available from outside the module) or abstractly (this implementation is restrained to the defining module, and the data constructors are not accessible from outside the module).

This mechanism provides a fine tuning over data encapsulation, which is mandatory for programming in the large.


Caml is a functional programming language: there is no restrictions in the definition and usage of functions, that can be passed as arguments or returned as values.

Automatic memory management and incremental garbage collection

Caml features automatic memory management: allocation and deallocation of data structures is kept implicit (there is no ``new'', ``malloc'', or ``free'' primitives), and handled by the compiler. This way programs are much safer, since spurious memory corruption can never occur.
Moreover, the memory manager works in parallel with the application, so that there is no noticeable stop of the Caml program when the garbage collector is running.

Imperative features

Caml provides full imperative capabilities, including updatable arrays, imperative variables and records with mutable fields.

Efficient compiler, efficient compiled code

Caml provides batch compilation, and separate compilation is obtained via the module system. The Caml compiler has a specific option to generate executable programs that maximizes the compilation speed, the portability of executables, and minimizes the size of the executables it generates (byte-code compilation).

The Objective Caml compiler also offers an optimizing compilation option to maximize the execution speed (native code compilation): the Caml native code compiler generates programs whose run times meet the highest standard of modern compilation.


Caml provides an interactive top-level ``read-eval-print'' loop, that is convenient for both learning, or rapid testing and debugging of programs: no need to use files, nor to add printing routines to the programs to check the results, since those results are automatically printed by the interactive system.

Symbolic capabilities

Caml features ``pattern matching oriented'' programming: this powerful programming method is a generalization of the traditional case analysis instruction. It is available for complex data types, in fact for any definable Caml data type. The pattern matching facility provides an elegant and clean way to ``test and bind'' the data arguments, in a single and concise operation. The Caml compiler takes advantage of this unique pattern matching feature to perform complex semantics verifications on the user's code: the compiler's pattern matching verifier is able to detect useless case branches (``this case will never happens at run-time'') and, more importantly, to detect when some case is missing (``this case is not covered by your program''). Hence, the pattern matching verifier points out many non trivial programming errors; in addition, the pattern matching verifier of the Caml compiler can provide static proofs of the exhaustive case analysis coverage of programs that use pattern matching.

Hence, the pattern matching facility gives an incredible ease and comfort when manipulating symbolic data.

The pattern matcher verifier provides a new level of safety and confidence for programs that perform symbolic treatment of data.

Error recovery

Caml has a general exception mechanism to handle or recover from errors or exceptional situations.

Debugging facilities

Several different methods are available to debug your Caml programs:


Caml features ``polymorphic typing'': some types may be left unspecified, standing for ``any type''. That way, functions and procedures that are general purpose may be applied to any kind of data, regardless of their types (e.g. sorting routines may be applied to any kind of arrays).

Evaluation regime

Caml is a strict language, as opposed to lazy ones. However, first-order value functions allows the manipulation of delayed expressions, and thus lazy evaluation of potentially infinite data structures is still possible.

Programming in the large

Huge Caml programs are made of (preferably many and small) compilation units. Hence, the Caml compilers feature separate compilation to handle the compilation units in a way that is fully compatible with the utilization of usual project management tools (such as the Unix make command). The module system is powerful and safe (every interaction between the modules is statically type checked by the compiler). Objective Caml modules can include other (sub-)modules at any depth, and functions from modules to modules are supported (to define modules that are parameterized by other modules).

Object oriented programming

Objective Caml features objects that give a fully fledged object oriented programming style in Caml programs. Faithful to the Caml language's philosophy, this object oriented extension obeys to the ``strongly type checked '' paradigm: as a consequence, a method can never be applied to an object that cannot answer it (``methods are always understood''). As usual, these systematic checks of the compiler point out a lot of errors. As a consequence, this ``strongly verified'' property of programs leads to an amazingly comfortable way of developing the code and grants the Caml programmer a significantly higher quality level of his object oriented programs.

Powerful libraries

There are a lot of libraries and contributions available in Caml, including portable graphics (libgraph), a package of multi-precision arithmetics (rational numbers), and various interfaces with well-known technology: lexer and parser generators with camllex and camlyacc. Under Unix, you also get the replay debugger, a Caml source browser (camlbrowser or ocamlbrowser), a user graphical interface using Tk/Tcl with camltk, and an interface with the operating system (libunix).

A taste of Caml

One hundred lines of Caml, using the interactive system, demonstrate the expressiveness of Caml.

Caml and education

Caml is used in education to teach programming courses, from beginners to graduate students. In this area, the automatic memory management and the type system are of prime utility.
Courses in the large for beginners are: CNAM (10000 students), option informatique des classes préparatoires aux grandes Écoles (1000 students).
Among courses for advanced students let me cite: École Polytechnique (100 students), and École Normale Supérieure (50 students).

Caml and applications

Caml is used to implement complex systems such as theorem provers or compilers. A good compiler written in Caml is Caml Light! The coq theorem prover is written in Caml. Ensemble, a toolkit for building distributed applications developed at Cornell University is written in Objective Caml. The web browser MMM is also written in Caml.

What next ?

For more information about the Caml Light system, see Overview of the Caml Light implementation.

For more information about Objective Caml, see the main page of Objective Caml.

Caml home page Last modified: Friday, March 26, 2004
Copyright © 1995 - 2004, INRIA all rights reserved.

Contact the author Pierre.Weis@inria.fr