CS790
MEng Project
Multithreaded
ML Interpreter
Suwat
Ch.
What is Caml ?
Contact the author Pierre.Weis@inria.fr
Original Page can be found at INRIA
homepage
Created in January 1996.
Caml is a programming language,
easy to learn, easy to use, and yet amazingly powerful.
It is developped 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.
Availability
Caml is freely available, and highly portable, since it runs under virtually
any Unix, PC, or Macintosh platform.
-
You can download Caml Light by anonymous ftp, from
the net, or on a CD-ROM. If you do not possess a CD-ROM device on your
computer, ask for floppy
disks that can be sent by surface mail by INRIA.
-
You can download Objective Caml by anonymous ftp, from
the net. Alternatively, you may get it on a CD-ROM.
To get the CD-ROM, mail to
INRIA-Diffusion
Distribution de Caml Light
B.P. 105
78153 Le Chesnay CEDEX
FRANCE
send an envelope (that can contain a CD-ROM), with your name
and adress.
Safety
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 they data accesses can be delagated 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:
-
basic types: integers, flotting point numbers, booleans, characters, strings.
-
more sophisticated data types: tuples, arrays, lists, sets, hash tables,
queues, stacks, data streams.
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 implémentation
is restreinted 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.
Functions
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'' or ``free'' primitives),
and handled by the compiler. This way programs are much safer, since spurious
memory corruptions 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.
Modules
Caml provides batch compilation, and separate compilation is obtained via
the module system. The Caml Light compiler generates executable programs
that are both small and portable.
Interactivity
Caml provides an interactive toplevel ``read-eval-print'' loop, that is
convenient for both learning and debugging: no need to use files, nor add
printing routines to get results.
Symbolic capabilities
Caml features pattern matching: it provides a concise, simple, and elegant
``test and bind'' facility for symbolic computation.
Error recovery
Caml has a general exception mechanism to handle or recover from errors
or exceptional situations.
Polymorphism
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.
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 a debugger, a Caml source browser (camlbrowser), a user graphical
interface using Tk/Tcl with camltk, and an interface with the operating
system (libunix).
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.
Back
to Top