OCaml for the Skeptical

Course Materials

Some History

Which ML?

OCaml is a dialect of ML (for Meta Language), which started out as a language for mathematical theorem proving in the LCF project at the University of Edinburgh1 and which is descended from Algol and Lisp via P.J. Landin's never-implemented language ISWIM ("If you See What I Mean" -- which was very influential due to several important journal articles in the late 1960's)2.

Development of ML proceeded at Edinburgh, Stanford and AT&T Bell Labs; at the Institut National de Recherche en Informatique et en Automatique (INRIA) in France as Caml (for Categorical Abstract Machine Language, after the underlying compilation technique); and at Chalmers in Sweden (as Lazy ML). The original line eventually became Standard ML, which has several notable implementations (Standard ML of New Jersey, MLton , Moscow ML 3, etc). Lazy ML strongly influenced Haskell and is no longer actively developed. Caml development continues at INRIA.

A Brief History of Caml by Guy Cousineau, the original developer, provides some insights.

Which Caml?

There are three "Caml" languages (at least: the excellent Caml compilers are very popular with researchers all over the world as a basis for experimental languages):

Caml : the original French implementation; no longer developed.

: the original French implementation; no longer developed. Caml Light (and later Caml Special Light ): the precursors to OCaml; practically the same as OCaml except for the object system that gives OCaml its "O"; still available, quite stable and still supported I think (latest release was in 2002), but I don't know why you would choose it over OCaml.

(and later ): the precursors to OCaml; practically the same as OCaml except for the object system that gives OCaml its "O"; still available, quite stable and still supported I think (latest release was in 2002), but I don't know why you would choose it over OCaml. Objective Caml or OCaml: the latest and greatest version of the language, introduced the first strongly-typed object system with type inference.

In summary, make sure you install and use OCaml and don't bother with the earlier Camls!

Standard ML and OCaml have minor syntactic differences. If you know OCaml, you can switch to ML very easily. The most important differences are in the libraries of the languages and in two significant OCaml advances: the object system (Standard ML has none) and the module system (very similar in basic use, though).

Getting OCaml

OCaml is installed on merlot.lib and you can use it there. It's in the FreeBSD ports, the NetBSD packages, and Linux rpms are available (Debian, Mandrake and RedHat reportedly install OCaml). Binaries for Windows and Linux are available from INRIA and, of course, OCaml is free software so you can always download and install from source; it compiles and runs on most every version of Unix (MacOS X included). For more information see Installing OCaml.

Third Party Software

The best one-stop-shopping site for third party OCaml libraries is The Caml Humps (newbies should go directly to the Caml Light / OCaml Hump).

OCaml Documentation

Official Documentation

OCaml User's Manual, incorporating:

and much more.

OCaml Books

Besides these books in English, there are eleven in French, and one each in German and Italian.

Developing Applications With Objective Caml , Emmanuel Chailloux, Pascal Manoury and Bruno Pagano, preliminary translation of the book Développement d'applications avec Objective Caml. This book is very good and typically O'Reillian; I highly recommend it.

The Functional Approach to Programming , Guy Cousineau and Michel Mauny, Cambridge University Press, Cambridge, 1998, ISBN 0-521-57183-9 (hardcover), 0-521-57681-4 (paperback) This book is a little more formal; most would probably consider it rather dry. Note that it covers the earlier language Caml rather than OCaml and so has no coverage of OCaml's object system nor the module system. But all the stuff about functional programming and types and syntax is applicable to OCaml.

The Little MLer, Matthias Felleisen and Daniel P. Friedman, The MIT Press, Cambridge MA, 1997, ISBN 0-262-56114-X Like the other Little books by the same authors (Lisper, Schemer, Java), this is not a conventional introduction to ML. It's a programmed text with a sense of humor that will either enlighten you or infuriate you. It assumes no previous familiarity with ML but covers very advanced topics very quickly. It is almost completely concerned with types. (N.B. while this is a book about Standard ML, it works fine for OCaml and the authors provide a one-page cheat sheet that explains how to translate the book's ML code into OCaml.)

Finally it should be mentioned that there are many books on Standard ML and all of these are quite usable by OCaml programmers, once you've gone through any of the books above (you do want to initially learn OCaml from an OCaml book, I think, but after that you can branch out into the literature of Standard ML).

OCaml Tutorials

I suggest doing these tutorials in this order, except for Kitt's, which, being so terse, is good to look at simultaneously with all of these.

OCaml Mailing Lists and Newsgroups

The official OCaml mailing list (archives) can also be read with your favorite news reader (which I highly recommend) thanks to the amazing gmane or directly via your browser.

There's also a list specifically for beginners (also available via gmane).

OCaml is also discussed on Usenet in comp.lang.ml (which also covers Standard ML) and comp.lang.functional (which covers all functional languages).

Footnotes