COMP 212: Functional Programming

Zoom link

Any class zoom events will be in this meeting.

Help Sessions

Sunday evening (Christian, Gavin), 7:30pm-9:30pm, Exley 109
Monday afternoon (Dan Licata), 2:50pm-4:30pm+, Exley 109
Monday evening (Haoran, Anan, Jared), 7:30pm-9pm, Exley 109 (except Exley 72 on Feb 12, March 4, April 8, May 6)
Tuesday afternoon (Dan Licata), 4:20pm-5:30pm, Exley 121
Tuesday evening (Gavin, Fernando, Jocelyn), 7:30pm-9pm, Exley 109
Thursday evening (Christian, Gavin), 7:30-9pm, Exley 109


Lab 1 (Dan, Gavin): Wednesday, 1:20pm-2:40pm, Olin 14
Lab 2 (Dan, Jocelyn): Wednesday, 2:50pm-4:10pm, Olin 14


Common recurrences


To install smlnj:

Mac OS

These directions worked on Mac OS Catalina/Big Sur/Monterey/Ventura.
  1. Start the Terminal application by selecting it from your Applications folder or by typing Terminal into Spotlight.
  2. If you don't have strong preferences about what unix shell you use, run
    	chsh -s /bin/bash
    (then type your mac password and hit enter when prompted) to switch your default shell to BASH from the new default of zsh. If you do have strong preferences about using zsh, then you will need to add the equivalent of the lines below setting your PATH and smlnj alias to your zsh startup files.
  3. Close the terminal and then open a new one.
  4. In the terminal, run
              xcode-select --install 
    Run the installer that pops up if one does; otherwise you already have the command line tools installed.
  5. Install the Homebrew package manager according to the directions on that page. I.e. copy the script into the Terminal and run it. At the end of the installation, it might (maybe only on Apple Silicon computers?) tell you two lines to run in the terminal, like
              echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.bash_profile
              eval $(/opt/homebrew/bin/brew shellenv)
    If it does, please do that. This sets some necessary environment variables, which point homebrew to the right location on your system. The location of the brew executable might be different than above on some systems (e.g. it might be /usr/local/bin/brew instead).
  6. In the terminal, run
    brew install rlwrap
  7. In the terminal, run
    brew install smlnj
  8. In the terminal, run
    echo 'export PATH="/usr/local/smlnj/bin:${PATH}"' >> ~/.bash_profile
  9. In the terminal, run
    echo 'alias smlnj="rlwrap sml"' >> ~/.bash_profile
  10. Close and restart the terminal and you should be able to run smlnj to start SML.
Work arounds:


These directions were tested on Windows 10. If you have an earlier version and this doesn't work, here are some old directions that might work.
  1. Use this installer.
  2. Install the VSCode editor and run SML in its terminal according to the directions below.
  3. If you get an error that sml.bat is not found, first try restarting VSCode. If that doesn't fix it, run PowerShell as an administrator and execute this command to add SMLNJ to your path (assuming SML is installed in the default location):
           [Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";C:\Program Files (x86)\SMLNJ\bin", [EnvironmentVariableTarget]::Machine)
    And then restart VSCode.

Text Editor

On a Mac, we recommend VSCode or Sublime Text or GNU emacs for editing SML source files. VSCode allows you to run a terminal inside of the editor, so you can run smlnj in there. emacs has a special mode for running SML code, but is less new-user-friendly. For Sublime, you can only run SML code from the separate Terminal application. On Windows, we recommend VSCode.


  1. Install VSCode and start it.
  2. On the left-hand side, you should see an icon that looks like three squares with one square sticking out. This is the place to install extensions. Install the following two extensions:
    • vscode-better-sml
    • Tomorrow and Tomorrow Night Theme from Microsoft. Click on this extension, and use the Set Color Theme button at the top to select one of the themes if it doesn't already prompt you to do so.
    This should make colorful syntax highlighting work for SML code.
  3. Create a folder for your COMP 212 work and select it via Open Folder... (Windows) or Add folder to Workspace... (Mac). You should put the .sml files you download from the course web site into this folder.
  4. You can start a terminal in VSCode by using the Terminal / New Terminal menu option.
  5. Type smlnj (Mac) or sml (Windows, if that doesn't work try sml.bat) to start SML.

Sublime Text

Sublime Text is available here; get version 4.

More specifically:
  1. Download the installer for your operating system. On Windows, follow the instructions in the installer. On Mac, navigate to your downloads and open the .dmg file. A pop-up containing your local Applications folder and a Sublime Text application file. Drag the Sublime Text file into the Applications folder.
  2. On Windows, you can open Sublime Text through the Start Menu. On Mac, you can open Sublime Text in one of three ways:
    • Finder: Open a new Finder window, navigate to your Applications folder (it should be listed in the left-hand column) and double-click on Sublime Text.
    • Terminal: In terminal, enter “cd /Applications ; open Sublime\“.
    • Launchpad: Open Launchpad and search for Sublime Text.
    You may want to put a shortcut to Sublime Text on your desktop/in your Dock.
  3. Install Package Control: Go to the Tools menu, click on Command Pallet, and then type Install Package Control.
  4. To get syntax highlighting, install the "SML (Standard ML)" package:
    1. Press on Tools > Command Palette in the menu bar and search for “install package”, then press enter with Package Control: Install Package.
    2. Search for “SML (Standard ML)” and press enter to install.
  5. To use SML highlighting, you may now navigate to View > Syntax > SML.


If you have Linux, you almost certainly have emacs installed. For Mac and Windows get:

To install SML syntax highlighting:

  1. Make a software directory in your home directory (to do this in the terminal, run mkdir ~/software/).
  2. Download sml-mode.tar and unzip it in your software directory (to find it outside the terminal, your software directory will be in software in your home directory on a Mac or in C:\cygwin\users\YOURNAME\software on Windows). This will create a directory ~/software/sml-mode-3.3-custom.
  3. Open Emacs, type Control-x Control-f to open a file, and then edit the line at the bottom of the screen to
            Find file: ~/.emacs
    and press enter. This is your emacs startup file.
  4. Copy the the contents of dotemacs-win.txt (Windows) or dotemacs-mac.txt (Mac) into this file. On Windows, you will need to edit the first line, replacing YOURNAME with your Cygwin user name. NOTE: The windows file is untested; let me know if you have problems.
  5. Save, close, and restart emacs.
  6. When you open emacs again and open a file.sml, it will now color the syntax. Also, you can run SML inside emacs as follows:
    • Control-c Control-b: load the current emacs buffer into the SML repl.
    • Control-c Control-s: pop up a separate window with the SML repl.

Some emacs resources:


If you used vim in COMP 211 and like it, we recommend this sml mode.