OCaml Notes



Objective Caml (OCaml) is a dialect of ML. You can learn more about it at the official site. You might be interested in a syntax comparison between OCaml and Standard ML.


A great place to start learning about OCaml is Jason Hickey's book. Some people also like ocaml-tutorial.org (mirror). Published books on ML include Ullman's Elements of ML Programming and Felleisen's Little MLer.  Here's some writing on OCaml internals.  There are lots of examples at the OCaml PLEAC page, or browse around group/code.  Here's a relatively new on-line tutorial.


We have a local copy of the documentation at file:///home/aifs2/group/bin/ocaml-3.12/htmlman/index.html.  A set of cheatsheets (including emacs commands) is here.


See the Emacs page for tips on programming environment.

If you have to use vim, you may want to look at omlet.


Those worried about speed should check out the computer language benchmarks game (click the "show" button). Xavier Leroy, OCaml's creator, says that \"My performance goals have always been 'never more than twice as slow as C'.\"  You should probably read these tips about writing fast code (don't forget the numerical section too).  Tips on tuning the garbage collector are here.


You might want to subscribe to the Caml Weekly News to keep up with what's going on in the OCaml community.


Someone should figure out how to install and use Elkhound, GSL, and LACAML.


For non-emacs users: top-level history and line editing can be achieved using rlwrap.  Alternatively, you can use ledit which is the same as rlwrap but it is written in OCaml.


OCaml at the UNH AI Group


On the AI group machines, OCaml binaries are in /home/aifs2/group/bin/x86_64-linux. ocamltop is a toplevel with many of the standard library modules (like Unix and Str) already compiled in.


The ocm program in that directory is useful for compiling. (Put Wheeler's .ocmrc file here as an example!)


The results database is a tool for storing and retrieving information from experimentation.


We also have a custom plotting tool called SPT.


OCaml library code

Can be found at /home/aifs2/group/code/.  This directory contains a set of mercurial repositories which you can clone.

Information about these repositories can be found at the Infrastructure page.

If you have ssh access to one of the AI machines (see the infrastructure page) then the following command should work:

  hg clone ssh://<username>@<machine>//home/rai/group/code/<repo>


Additionally there is a set of shell scripts available in /home/rai/group/bin which can make your life easier:



Takes one opitonal argument (a machine name), and clones all of the repositories.  If the machine name argument is omitted this script will try to clone the repositories from the local filesystem instead of ssh.



Assumes that each sub-directory in the current directory is a mercurial repository, it then enters each repository and does a 'hg pull.'   If the pull shows that there are updates then the updates are performed.  If there are merges required a message is printed and merges can be done by hand.



Fetches (pulls,updates,merges/commits) each sub-directory in the current directory.  You need to have the fetch extension in your ~/.hgrc file:


fetch =



Same as pull_all.sh except instead of pulling, it does 'hg incoming' to see if a pull would have any updates.



Creates an empty repository in /home/rai/group/code and gives everything the correct permissions.  To use it, just run it and give it the name of the repository as the argument.


All of the libraries use 'ocm' to build.  Ocm is in one of the repositories, however it has a makefile which can be used to build it (ignore the warnings).



Clean all of the files that OCM generates.  This should be run from the directory that contains your system directories.  You only need to run this on rare occasions when the repositories get out of sync with the .cmi and depend files.


OCaml at the UNH CS Dept


OCaml is installed in ~cs980/bin on agate.cs. Documentation is at ~cs980/ocaml/htmlman/index.html.


OCaml at UNH CISunix


There is an installation at ~wri5/ocaml. The compilers are in the ocaml/bin directory there, and the documentation is at ocaml/htmlman/index.html.