Software setup

OCaml

We will do most of our programming this quarter in OCaml (as well as other languages we create). To install OCaml, we will use OPAM, which is the OCaml ecosystem's package manager.

If you just want to try out a quick idea, you can use the OCaml Playground. You must still install OCaml on your machine, though, because some of our projects will require more complex build setups than those supported by the playground.

Step 1: Installing OPAM

Windows

The OCaml community is rapidly improving its support for Windows, but things are still in flux. There are three possible ways to do it: via WSL2 (Windows Subsystem for Linux), via "OPAM for Windows" (which uses Cygwin), or via the DkML installer (native Windows). Confusingly, these are all completely separate and unrelated to each other.

  • If you have Unix experience (e.g., Linux, macOS), or are interested in becoming more familiar with Unix (it's good for you), we recommend using the WSL2 approach.

  • If you are already familiar with Cygwin, you may like the "OPAM for Windows" approach. Otherwise, we don't recommend this for anyone.

  • If you like Windows PowerShell or Command Prompt, or if you prefer Windows native solutions, then we recommend the DkML installer.

If none of these approaches work for you, you can try one of the "Alternate approaches" at the bottom of this page.

via WSL2

  • Install WSL2 if you don't already have it. Instructions

    • WSL allows you to run a Linux environment directly on Windows without dual booting or a traditional virtual machine (VM).
  • Inside of WSL, install make and a C compiler via

    • sudo apt install build-essential
  • Now follow the Linux, macOS, and WSL instructions below.

"OPAM for Windows" (which uses Cygwin)

  • This method is only recommended for those with prior experience using Cygwin.

  • Follow the instructions on the "OPAM for Windows" page.

    • Use the 64-bit graphical installer
    • If you get a virus-scan failure on the graphical-installer download, try "save link as" from an incognito browser window.
  • After installation completes (it takes a while), open the cygwin shell created in the previous step, called something like cygwin64 Terminal, and proceed to Step 2.

    • If you already had cygwin installed, you now have a second one installed. This is no problem, but you will need to keep track of "which is which" and open a terminal for the cygwin you just created here for the instructions that follow and whenever opening vscode.

via DkML

  • Follow the instructions under the section called "1. Use the DKML Installer" (and only that section).

  • Proceed to Step 2.

Linux, macOS, and WSL

  • Follow the instructions on the official OPAM page with these caveats:
    • You can use the binary installer at the top of that page, or you can use the package manager for your flavor of Unix (on WSL, that would be Ubuntu).
    • On WSL:
      • Before following those instructions, run sudo apt install unzip.
      • After following those instructions, run opam init --disable-sandboxing --reinit
    • On macOS:
      • If you don't have the XCode command-line tools installed, you will need those.
        • Run xcode-select --install

Step 2: Use OPAM to install packages

  • Run
    • opam install dune utop ocaml-lsp-server
  • (You can leave off ocaml-lsp-server if you don't plan to use an IDE such as VS Code.)

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

Install the OCaml Platform extension to VS Code by clicking the big green button at the top of this page

If you used the Cygwin method ("OCaml on Windows")

If you used the Cygwin method ("OCaml on Windows"), then you must open VS Code from inside the Cygwin terminal, not by clicking the VS Code icon.

Every time you want to open VS Code, instead you should open Cygwin terminal and run this command:

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

Configuring utop (Completely Optional)

Decluttering utop like in lecture

In your home directory, create a file .config/utop/init.ml with these contents:

#utop_prompt_dummy;;
UTop.set_show_box false

Syntax highlighting in utop

In your home directory, create a file .utoprc with these contents:

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

Alternate approaches to working on CSE 341 assignments