Using SML

This guide is to help you get used to using the ML interpreter for your homework assignments. First I'll give some general advice on the easiest way to work. Then I'll explain what you need to know or do depending on where you choose to work-- both what platform you prefer and whether you want to work in the lab or on your own computer.

The game of the name

In addition to "ML", you will sometimes see the name "SML." The "S" is for "Standard," so this indicates a particular variety of ML. Since SML is the version of ML we're using, "SML" and "ML" are synonymous for our purposes. You also may see "SMLNJ" or "SML/NJ", which stands for "Standard ML of New Jersey." This refers to the implementation of SML that we're using. It was developed (initially) at Princeton University and Bell Labs---since both of those are in New Jersey, that's how the software got its name.

General working procedures

Since you will usually need to make corrections to your code as you go along, and since you will always want to turn in your completed code, you will want to have two windows open. First, you need the ML interpreter window; second, you should have a text editor window. Use the text editor to write the code. When you think it's right, copy and paste it into the ML interpreter. If you get an error, then make some corrections in the text editor and try again. Use the text editor to save your work to a file. Then, for each problem, go to the turn-in page and submit.

Where to work

You can do your work in the main CS lab (Olin 124), in the upstairs CS lab (Olin 228), in the Math Lab (Olin 207), or on your own computer. The advantage of working in the CS lab is that you can learn from your classmates who are there working near you.

In the CS lab

If you already are familiar with the CS lab (from taking CS 167, for example), then this should be your favorite place to work. Everyone else is welcome to work there, too---in fact, encouraged to do so because that's where you can get help from others working on the same problems.

The CS lab machines use an operating system called Ubuntu (a distribution of Linux). If you haven't used a system like that before, your best bet is to find a friend who has and ask that person to give you a quick tour. It isn't too hard to learn it well enough to be able to do all you need for this course. If you like, you can work through this introduction and tutorial.

In the upstairs labs

The upstairs labs have the same software installed, but you may not find other students working on homework for this class. It may be a bit quieter, especially in Olin 228.

At home

You can install the ML interpreter on your own computer. SML/NJ is freely available for download for Linux/Unix, Macintosh, and Windows. See for the software homepage or for the downloads page.

If you are downloading it to use on a Mac, you will need to run it through the terminal, which you can find under Applications->Utilities->Terminal (you'll probably want to add Terminal to your dock for the semester). However, there may be one last step you need to do after it installs to make sml convenient to use. Details:

The installer will put the binary for sml some place that is not in your path. The latest version I've used installs sml to /usr/local/smlnj/bin. Once the installer finishes, you can confirm that it works by running the interpreter as /usr/local/smlnj/bin/sml. If that works, then the final step is to change your PATH environment variable to include that bin folder. Open the file .bash_profile in your home folder (or make that file if it doesn't exist) and include the line export PATH="$PATH:/usr/local/smlnj/bin/" Save the file and open a new terminal window. You now should be able to start the interpreter with just sml.

If you don't know what those details meant, then stop by my office or Dustin Palmer's office and it will take me around 30 seconds to fix up your computer.

Connecting to the lab remotely

Follow these instructions to log in to a lab computer remotely from your own computer using SSH. If you have difficulty, bring your computer to the lab and get help from Dustin Palmer (Olin 126, during work hours) or the lab aide on duty (Olin 124, after hours).

Platform specific information

Linux and other UNIX

GEdit and Xemacs have modes for a language called Objective CaML, which is related to ML. These should help you make your ML programs nice and pretty. Don't forget that to copy and paste, all you need to do is highlight the text and then middle-click into the window where you want to paste.

You are also welcome to use Brackets or Vim.


If you're not familiar with "text editors", it just refers to a program that's similar to a word processor, but a lot simpler. The standard one that comes with MacOS is called "TextEdit", and you should find it under "Applications" on your computer. Copying and pasting between the two programs shouldn't be too hard---it's a Mac, after all.


The standard text editor in Windows is NotePad. Copying and pasting between NotePad and SML is a bit tricky: Highlight in NotePad and copy it as you normally would (either from the Edit menu or using shortcut keys); then right-click in the ML window and select "paste." If you ever need to copy and paste from the interpreter to NotePad, then right-click in the interpreter window and select "mark"; drag over the code you want to copy; press enter; and then paste into NotePad.

Downloading code from the Web

Code written in SML is normally saved in a file with the .sml file extension. Handily, the author of our textbook provides source code for textbook examples and exercises. At times I will also share example code developed in class through the course web site. Try downloading one of these files and see what happens.

Unfortunately, most computers are configured to believe that .sml files are used for some other purpose. For example, on the Ubuntu Linux computers in the lab, if you download a .sml file it will be opened in a movie editing program.

To fix this problem, you will need to change the file associations used by your operating system or web browser.

Janet Davis ( Adapted from a similar guide by Thomas VanDrunen.

Created September 2, 2016
Last revised September 05, 2016, 10:03:53 AM PDT
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.