Compilers

OCaml Setup

Before you can complete any lab assignments, you’ll need to have a working OCaml compiler toolchain. The manner in which you configure this depends upon what kind of system you will be using.

CS Department Machines

The CS department machines provide an installation of Ubuntu Linux which supports OCaml quite well, but you have an insufficient disk quota to install a personal version of OCaml. You can instead use a shared instance for this course. To configure your account to use this instance, you should only need to do the following:

  1. Open ~/.bashrc in a text editor (e.g. vim ~/.bashrc).

  2. Add the following line to the very bottom of the file:

    source /home/zpalmer/public/cs75/s19/environment.sh
    

    If you like, you can cat that file to see what it’s doing.

  3. Quit your text editor and run the following command: source ~/.bashrc

By default on the CS department machines, the .bashrc file is executed for each new Bash shell you create (via SSH, terminal window, etc.). The command we added will ensure that you are using the course’s common installation of OCaml, which contains all of the tools and libraries you will need to compile OCaml programs in this course.

Personal Linux Computer

Most Linux distributions include a piece of software called OPAM (e.g. sudo apt-get install opam). OPAM is an OCaml package manager (similar to e.g. pip for Python) that makes it easy to install OCaml libraries. First, install OPAM on your computer.

Once OPAM is installed, run the following commands:

opam init
opam switch 4.06.1
eval `opam config env`
opam install batteries menhir merlin monadlib ocaml-monadic ocp-indent ounit ppx_deriving user-setup ppx_tools tuareg

We might not use all of the installed packages, but they’re handy to have and may prove useful throughout the semester. After running these commands, everything should be set up properly.

For the later compilers labs, you should make sure you have clang, nasm, and C development packages installed on your computer. On an Ubuntu or Debian system, the following should be sufficient:

sudo apt-get install libc6-dev libgcc6-dev nasm clang

Personal MacOS Computer

The best way to install OCaml on a computer running macOS is to install Homebrew, an unofficial package manager. Once you have installed Homebrew, you can then install OPAM, the OCaml package manager, by running the following command:

brew install ocaml opam

With OPAM installed, you should be able to set everything up by following the Linux instructions above.

Personal Windows Computer

Installing OCaml on Windows is somewhat more difficult given that Windows is not generally compliant with POSIX standards. That said, the process is made somewhat easier by the OCaml Installer for Windows.

Specifically, you can try following the instructions on their Wiki to get install OPAM on Windows. Follow the instructions carefully! At the bottom of the list of instructions is a section called “Install a bunch of opam packages” which asks you to run an opam install command in Cygwin. Instead of running the given command, run the opam install command from the Linux installation instructions above. If all of these steps complete successfully, you should now be able to compile OCaml programs on your Windows computer.

It’s also worth considering virtual machine software such as VirtualBox. If you install a Linux virtual machine on your Windows computer, you can then follow the Linux instructions above and likely have a smoother development experience.