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.
Option 1: Recommended VM Setup
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.
- Install VirtualBox.
- 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:
- If the VM looks too small, consider increasing the scaling that VirtualBox does by navigating to the VirtualBox preferences on your host machine, selecting the display settings, and increasing the scale factor to around 200%.
- In the Ubuntu distro, click the Applications button in the bottom-left part of the desktop, then open the Settings app. From there, navigate to the display settings, and adjust the resolution.
Option 2: Recommended Manual Setup
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.
-
Install
opam
, preferably using your system’s package manger (e.g. Homebrew for macOS orapt
for Ubuntu). This link provides more detailed instructions. (On macOS you may need tobrew install gpatch
first.) -
Initialize
opam
(the OCaml package manager) by typing the following command in your terminal:opam init
. You can allowopam
to modify your shell’s configuration, but answer “no” to the question about hooks. If you do not allowopam
to modify your shell’s configuration, make sure that you have your shell run the following command on startup:eval $(opam env)
forbash
-like shells (e.g.bash
orzsh
) oreval (opam env)
forfish
. For the sake of platform agnosticism, I will abbreviate this last command aseval-opam-env
. -
Run the
eval-opam-env
command now. -
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
. -
Run the
eval-opam-env
command again. Check that theocaml -version
command indicates that you have version 4.12. -
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
. -
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
. -
We will now install
ocamlformat,
an autoformatter for OCaml. To do so, run the following command:
opam install ocamlformat
. - Install Visual Studio Code.
- Finally, within Visual Studio Code, install the OCaml and Reason IDE extension.
- 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:
-
dune
, the most popular OCaml build tool -
utop
, a fancy OCaml REPL -
ounit2
, for unit testing -
ppx_deriving
,ppx_inline_test
,ppx_let
,ppx_blob
, for metaprogramming (used by some skeleton code we provide you) -
shexp
, for executing shell commands from OCaml (used by some skeleton code we provide you) -
core
, standard library replacement from Jane Street (used by some skeleton code we provide you) -
yojson
, JSON library for OCaml
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