Compilers

OCaml Local 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/s22/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.

Remote Access

If you wish to use your personal computer to do your coursework but would like to avoid installing OPAM and the OCaml compiler and libraries on your own machine, you can work remotely. You still need to complete the steps in the CS Department Machines section above on the CS network, although you can do so remotely using an SSH client. See the Remote Setup guide for more information.

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 create 4.13.1
eval `opam env`
opam install batteries dune 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. One approach is to install the Windows Subsystem for Linux, which allows a Windows machine to approximate the behavior of a Linux system. Next, one might install OPAM within that subsystem. This is a fair amount of work but, as of the time of this writing, a native Windows-compatible OPAM installer is still under development and is expected to be released with OPAM 2.2.

One alternative is to install 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.