Programming Languages and Compilers

CS 164 @ UC Berkeley, Fall 2021

This is the Fall 2021 website. If you are currently taking CS 164, please go to https://inst.eecs.berkeley.edu/~cs164/fa22/.

Software

We’ll be using OCaml in CS 164, which requires only a text editor and a terminal. You’re free to use whatever text editor or IDE you prefer, but we strongly recommend you follow one of the two recommended setups below, as we will be unable to provide guidance on any other setups if they are not working correctly.

The recommended VM setup is quick and easy (especially for Windows users), but requires that you do your work for CS 164 in a virtual machine.

The recommended manual setup, on the other hand, is a bit more work (and we will not be able to provide full support for every system configuration), but it enables you to do your work for CS 164 on your normal operating system.

The CS 164 (Fall 2021) VM is a Linux (specifically, Ubuntu 20.04 LTS) virtual machine with all the software you will need for this course. In particular, it includes all the OCaml command-line tools and packages as well as Visual Studio Code (the recommended text editor for CS 164) preloaded with an OCaml language extension.

  1. Install VirtualBox.
  2. Download the CS 164 (Fall 2021) VM and open it in VirtualBox.

The username and password for the VM are both student.

You will likely need to adjust the resolution of the VM. Here are two tips to do so:

Note for Windows users: OCaml is somewhat notorious for being difficult to install on Windows. Our recommendation for Windows users is to follow the recommended VM setup, but if you strongly prefer to follow this manual setup, we recommend installing and using the Windows Subsystem for Linux in the following steps and throughout the course.

At a high level, we’re first going to install the OCaml package manager opam, then use opam to install OCaml and some related tooling. Next, we’ll install Visual Studio Code for our text editor and an OCaml plugin for Visual Studio Code for a better coding experience. Finally, please be sure to install the necessary packages for CS 164 , even if you do not follow the other steps.

  1. Install opam, preferably using your system’s package manger (e.g. Homebrew for macOS or apt for Ubuntu). This link provides more detailed instructions. (On macOS you may need to brew install gpatch first.)
  2. Initialize opam (the OCaml package manager) by typing the following command in your terminal: opam init. You can allow opam to modify your shell’s configuration, but answer “no” to the question about hooks. If you do not allow opam to modify your shell’s configuration, make sure that you have your shell run the following command on startup: eval $(opam env) for bash-like shells (e.g. bash or zsh) or eval (opam env) for fish. For the sake of platform agnosticism, I will abbreviate this last command as eval-opam-env.
  3. Run the eval-opam-env command now.
  4. Install the latest version of OCaml using opam (not your system’s package manager). This can be done via the following command: opam switch create 4.12.0.
  5. Run the eval-opam-env command again. Check that the ocaml -version command indicates that you have version 4.12.
  6. We will now install Merlin, a tool that provides some helpful features in the development of OCaml programs (e.g. autocomplete, type information). To do so, run the following command: opam install merlin.
  7. We will now install ocaml-lsp-server, which lets editors such as Visual Studio Code interact with Merlin. To do so, run the following command: opam install ocaml-lsp-server.
  8. We will now install ocamlformat, an autoformatter for OCaml. To do so, run the following command: opam install ocamlformat.
  9. Install Visual Studio Code.
  10. Finally, within Visual Studio Code, install the OCaml and Reason IDE extension.
  11. You also need to install the nasm assembler using your system’s package manger.

Necessary Packages for Manual Setup

Regardless of which editor you use, you will need the following packages for CS 164:

You can install all these packages at once with the following command:
opam install dune utop ounit2 core shexp menhir \
ppx_deriving ppx_inline_test ppx_let ppx_blob yojson
.