We use two functional programming languages in COS 326 course: OCaml and F#.
OPAM is the package manager for OCaml. It is the recommended way to install the OCaml compiler and OCaml packages. -OCaml installation instructions
Once Opam is installed, the same instructions work on all platforms. But the installation of Opam will work differently on different operating systems.
- If you do not have Homebrew installed (run
brewin Terminal to see), install Homebrew. brew install opam ocaml- If you want to use
emacsas your text editor, alsobrew install emacsbecause Mac OS X comes with an out-of-date version of emacs.
- Use your system package manager to install the
ocamlandopampackages.
Because Windows does not have a Unix shell built in, we have to install one. There are several methods for doing this, including:
- with Microsoft's Windows Subsystem for Linux (also called "Bash on Ubuntu on Windows")
- with Cygwin (a third-party tool for installing Linux programs natively on Windows)
- with a remote SSH connection to the
cycles.cs.princeton.eduLinux computers, which already have OCaml installed - with OCPWin (a self-contained OCaml installer using the native Windows command prompt)
- with a virtual machine installation of Linux, using VirtualBox
- with a physical installation of Linux as a second operating system, so you chose which operating system to load when you start up your computer
I recommend you try these methods in the order presented above. I will provide instructions for the first three.
The Windows Subsystem for Linux (also called "Bash on Ubuntu on Windows") is Microsoft's compatibility layer to run Linux programs within Windows.
- Open PowerShell as an administrator (right click; Run as Administrator) and run
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux - Restart when requested
- Install the Ubuntu app from the Get Ubuntu page on the Microsoft Store.
- Open the Ubuntu app and set your username and password. Note the username cannot have spaces, and the password won't show while you're typing it.
- Once you have opened the Ubuntu app once, we will remove the Windows Subsystem for Linux from the Windows Defender Real-time Protection, which is necessary or else all programs in the Ubuntu shell will run very slowly:
- Download
excludeWSL.ps1this GitHub link using the 'Download Zip' button and then copyexcludeWSL.ps1out of the zip into your Downloads folder. - Then open PowerShell as an administrator again and run the following commands:
cd C:\Userslsto see what your username is (the subfolder not named 'Public' will be your username)cd .\username\DownloadsSet-ExecutionPolicy Unrestricted.\excludeWSL.ps1- Type
rforRun onceand the script will add a bunch of exclusions to the Windows Defender paths. Set-ExecutionPolicy Restricted- Close PowerShell and reopen the Ubuntu app.
- Download
- Install Xming if you want graphics support for
emacs.- If you do, add
export DISPLAY=:0to your~/.bashrc(open~/.bashrcfrom the Ubuntu terminal with your preferred text editor) so that Linux programs can connect to the Xming display server while it is running.
- If you do, add
- Run the following commands in the Ubuntu app:
sudo apt updatesudo apt dist-upgrade -y(This takes a while.)sudo apt install -y opam ocaml emacs vim m4(This takes a while too.)
- Using the Ubuntu app (not the Windows Command Prompt) go to Setting Up OCaml below.
- Download the 64-bit graphical installer from OCaml for Windows.
- Step through the installer.
- It will open Cygwin setup.
- Step through this.
- Select a mirror (a website which hosts packages to install). I used mirrors.kernel.org.
- If you want to use
emacs, then when you get to the 'Select Packages' screen, select the 'Full' view and search for 'emacs'. Click on theemacsline where it says 'Skip' so it changes to a version number. Repeatedly click it - this will rotate between all the possible versions. Leave it with the highest version selected. Then hit Next. - It will take a while to download and install Cygwin.
- Then you will be back in the OCaml setup.
- In the future, you can use setup-x64_64.exe from Cygwin Installation to update or install the packages in the Cygwin system.
- Open the Cygwin64 Terminal (instead of the Windows Command Prompt) and go to Setting Up OCaml below.
This is essentially the approach you would have used in COS 217, except that you will connect to cycles.cs.princeton.edu instead of courselab.cs.princeton.edu.
I am assuming you had issues setting up both WSL and Cygwin, and so these instructions will not use either of those programs.
- Set up your CS department account, if you have not done this.
- Install MobaXterm Home Edition (free edition)
- Select Session -> SSH
- Connect to
cycles.cs.princeton.edu
Run the following commands in the Unix terminal (Terminal.app on Mac OS, Ubuntu app or Cygwin Terminal on Windows):
opam --version. Note whether you are onopam < 2.0oropam >= 2.0.opam init- Say
ytoDo you want opam to modify C:/OCaml64/home/kathe/.bash_profile? [N/y/f] - Say
ytoA hook can be added to opam's init scripts to ensure that the shell remains in sync with the opam environment when they are loaded. Set that up? [y/N]. If this is missing, runopam init --enable-shell-hookmanually. eval $(opam env)(if you haveopam < 2.0, such as1.2.2, then runeval $(opam config env)instead).- Now run
opam switch. This will tell you you are using the system compiler. opam install tuareg merlin user-setup ocamlbuild ocamlfind ocp-indent- Run
which ocamlto check that theocamlcompiler is installed. - Run
which ocamlfindto check thatocamlfindis installed. - Run
which ocamlbuildto check thatocamlbuildis installed. - Run
opam user-setup installto configuremerlininemacsandvim.
Follow Option 1 or Option 2 from Use F# on Mac OSX.
Follow the instructions for your distribution at Use F# on Linux.
Follow Option 1 or Option 2 at Use F# on Windows.
For OCaml, the copy of emacs you run from the same terminal as opam is available should have Merlin set up automatically by opam user-setup install above.
For F#, install fsharp-mode from MELPA.
Mac OS users: we recommend you use brew to update emacs as described above.
For OCaml, the copy of vim you run from the same terminal as opam is available should have Merlin set up automatically by opam user-setup install above. You can also install rgrinberg/vim-ocaml for some additional features.
For F#, use fsharp/vim-fsharp.