OCaml Software
Setup

Installing OCaml and Related Tools

We will use opam, OCaml's package manager, to install OCaml as well as various libraries and tools.  We recommend (but do not require) the Visual Studio Code editor (referred to as VS Code).

This guide from ocaml.org provides a tutorial walk through for installing OCaml: 

Up and Running with OCaml

But before working through the general information above, read on for specific instructions we believe will work and suffice for CSE 341 based on our own experience.  Please speak up on the discussion board if you run into problems after following these steps carefully, so we can improve these notes.  If they don't make sense, please ask!

Here is what we have found to work:

Windows (preferred method)

Windows (alternate method)

Linux, MacOS, and WSL

opam init --disable-sandboxing --reinit

2. Use opam to install dune, utop, and ocaml-lsp-server

opam switch create ocaml-base-compiler.4.13.1 

opam install dune utop

opam install ocaml-lsp-server

You can learn more about managing your opam installation from the opam usage guide, but you don't need to.

Alternatively, instead of installing everything on your system, you can choose to use attu (remote CSE Linux cluster, available to CSE students only), which has an OCaml installation. From a terminal, run ssh <CSENetID>@attu.cs.washington.edu and use your CSE login as the password. VS Code also has SSH support (instructions below). However, the OCaml version installed by default on attu might be outdated, which could be an issue on some assignments. You can, if needed, follow these instructions to install an up-to-date version of OCaml in your attu home directory.

As yet another alternative, OCaml should already be installed on the CSE lab machines.

As a final alternative, The UW CSE Virtual Machine is a CentOS Linux set up to approximate the set up on Allen School lab computers. Roughly speaking, it will let you run a fresh, full-fledged Linux machine as if it was just another application. If you are struggling to set up software on your personal computer, you may have better luck by:

3. [Optional-but-possibly-helpful] Configure utop as used in lecture

You can do either or both of these things:

UTop.set_show_box false

profile:                  light

identifier.foreground:    none

module.foreground:        x-forestgreen

comment.foreground:       x-firebrick

doc.foreground:           x-violetred4

constant.foreground:      x-darkcyan

keyword.foreground:       x-purple

symbol.foreground:        x-purple

string.foreground:        x-violetred4

char.foreground:          x-violetred4

quotation.foreground:     x-purple

error.foreground:         red

directive.foreground:     x-mediumorchid4

parenthesis.background:   light-blue


Installing Visual Studio Code (VS Code) and Extension(s)

Install VS Code

The VS Code website provides installers for Windows, Linux, and MacOS.

Note: if you installed OCaml via WSL on Windows, follow these instructions to develop in WSL using VS Code. This will let you edit files in WSL using VS Code and use the terminal in WSL to use your OCaml installation.

Install the OCaml Extension

Opening VS Code -- Crucial Information for Windows Users (Cygwin)

On Mac, Linux, and WSL, you should be able to open VS Code however you want and have the OCaml Extension work correctly with the utop REPL, etc.  

But on Windows without WSL (i.e., if you are in Cygwin), the bottom of the OCaml "up and running" instructions contain this key information: On Windows, we must launch Visual Studio Code from within the Cygwin window, rather than by clicking on its icon (otherwise, the language server will not be found):

$ /cygdrive/c/Users/Frank\ Smith/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe

In other words, do not launch VS Code like a normal application.  Instead, every time you want to launch VS Code open the cygwin terminal and type something like the above, replacing "Frank\ Smith" with your Windows account name on the computer you are using.  

However, that can be annoying, so here is a slightly less annoying approach.  You just have to take these steps one time:

alias vscode="/cygdrive/c/Users/Your\ Name/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe"

Now every time you want to open VS Code and use utop within it, you still need to open a cygwin terminal, but now you can just type vscode and hit return.

If using attu

If you chose to use attu, install the Remote-SSH extension to develop on attu within VS Code.


UW CSE VM

The UW CSE Virtual Machine is a CentOS Linux set up to approximate the set up on Allen School lab computers.

Roughly speaking, it will let you run a fresh, full-fledged Linux machine as if it was just another application.

If you are struggling to set up software on your personal computer, you may have better luck by: