Caml
Power

Using a Virtual Machine Environment

We will provide a virtual machine environment pre-configured for use in the course. If you have a Windows machine, you should use this option. Some of the libraries we will use in this course are not natively supported on Windows. This is is also a fine option for Mac or Linux users.

You can install the VM software from https://www.virtualbox.org

This course's pre-configured Ubuntu image can be downloaded from the course site. WARNING: It is quite large (2.8GB), so we recommend a wired connection if possible. The image's MD5 hash is 46d0a0d9e033c93a8e04aed32cb08d49, if you would like to verify the download integrity.

To run the pre-configured Ubuntu image, use VirtualBox's "Import Appliance" command (from the File menu). Choose "Open appliance..." and select Ubuntu326.ova, which you just downloaded, then click "Import". Importing the image will require approximately 12GB of disk space. Once the image has been imported, you should be able to start the machine. At the login screen, the password for COS326Student is princeton.

The remainder of the installation intructions should not be necessary if you are using the VM image, however you may find the discussion about the Emacs keyboard shortcuts to be useful.

Installing OPAM

Install the OCaml package manager OPAM. OPAM is the quickest and easiest way to get all kinds of libraries for OCaml programming. To install on your platform, follow these instructions.

On Mac OS X, install Homebrew first. Then, from the Terminal, run:

$ brew install opam

On 64-bit Ubuntu Linux, run the following commands from a terminal:

$ sudo add-apt-repository ppa:avsm/ppa
$ sudo apt-get update
$ sudo apt-get install ocaml opam

Alternatively, you can follow the OPAM Quick Install guide.

Text Editors

You can develop Ocaml programs using any text editor. If you already are comfortable with Emacs, Vim, or Eclipse, proceed to the instructions regarding your editor of choice. If you are indifferent, I recommend Emacs with Merlin. Merlin also has a front-end for Vim, though I personally use Emacs and have only tried that. Eclipse offers some other OCaml plugins.

Emacs

To install Emacs on a Mac, follow the instructions here under the heading "Homebrew." To install Emacs on Ubuntu, run the following command from a terminal:

$ sudo apt-get install emacs24

Tuareg Mode

Tuareg mode is a special mode for editing OCaml files in Emacs. You'll want to use Tuareg mode whether or not you choose to install Merlin; Tuareg mode provides syntax highlighting, indendation, etc., while Merlin helps with programming logic. Tuareg is now available via OPAM:
$ opam install tuareg

Once the install completes, there are instructions indicating the lines of code you should copy in to your .emacs file. Cut and paste those lines in to your .emacs file, adjusting the placeholder variables to be the correct path, as stated in the instructions given by OPAM.

You can also find the Tuareg software and installation instructions on the Tuareg page. From that page, click on released files. Download the latest version. Look at the README and follow the instructions. (Warning: this is more complicated than just using OPAM to do it.)

Once you have installed OCaml and Emacs, open any file with a .ml or .mli extension. This should start up Tuareg mode and you should see OCaml key-word, comment color highlighting and other features. To start the OCaml top-level interpreter in Emacs, on Windows at least, make sure the OCaml bin directory is in your path. At this point, you should be able to type C-c C-s in Emacs and the OCaml top-level interpreter will start. Alternatively, you can start OCaml from the Tuareg pull-down menu by choosing "Interactive Mode" and then "Run Caml Toplevel."

Merlin Mode

To install Merlin, type:
$ opam install merlin

Once the install completes, there are instructions indicating the lines of code you should copy in to your .emacs file. Cut and paste those lines in to your .emacs file.

Merlin supports several nice features within Emacs. For example:

  • M-x merlin-mode: begin using Merlin mode (also starts whenever you load a .ml file)
  • C-c C-t: type check the expression your cursor is on
  • C-c t: type check an expression in the type checking context at your cursor
  • C-c C-l: when your cursor is on an identifier, jumps to the code that binds that identifier
  • C-c C-n: jumps to the next OCaml phrase in the code
  • C-c C-p: jumps to the previous OCaml phrase in the code
  • C-c : tries to auto-complete the current identifier
  • M-c : tries to complete the current identifier in our VM image, which does not have Emacs24 auto-completion

Check out this link on Emacs from scratch for more information on using Merlin with Emacs.

Vim

To install Merlin, type:
$ opam install merlin

Check out this link on Vim from scratch for more instructions.

Eclipse

Many of you develop Java programs using Eclipse. There are three OCaml plugins for Eclipse available in various states of development. (There is also a stand-alone OCaml IDE from Brown called Camelia, which we had a lot of trouble with and do not recommend.)

Of the three OCaml plugins for Eclipse, people have had the best luck with OcaIDE. It requires at least Eclipse 3.5 (Galileo), but we recommend upgrading to Eclipse 3.6 (Helios). My sources tell me there were no problems installing it on Ubuntu or on an Intel-based Mac running Mac OS X 10.5 (Leopard) following the online instructions.

These OCaml set-up notes come in part from Dexter Kozen, Nate Foster and Arjun Guha.

Real Programmers use Emacs

Using the CS department servers

For CS majors or other students with CS accounts, you can use OCaml version 4.00.1 on penguins. In your shell's configuration file, e.g. .bashrc, include the following command in order to select Ocaml4 every session:

module load ocaml4

Note that tuareg mode and merlin are not available on these servers.

Acknowledgement

These OCaml set-up notes come in part from Dexter Kozen, Nate Foster and Arjun Guha.