SML/NJ setup on OSX

SML/NJ is a compiler and programming environment for the functional programming language Standard ML. We used this language as part of the CSE505 – Fundamentals of Programming Languages course by Assistant Professor Lukasz Ziarek in Fall 2013.

I installed SML/NJ 110.77 on my Macbook running OSX 10.9. The .pkg file listed under MacOSX can be downloaded from http://www.smlnj.org/dist/working/110.77/index.html. Run the file and follow the instructions to get SML installed on your machine.

Though SML is installed now, if you run SML in the terminal, you’ll get the ‘command not found’ message. This is because UNIX doesn’t know where to find the executable for SML. The SML executable can be found at /usr/local/smlnj/bin/sml. The path to this executable should be made available to the PATH environment variable so that when you type ‘sml’ in the terminal, UNIX knows where to find it. This can be done by adding the following line to ~/.bash_profile file:

After saving the file, we need to run the ~/.bash_profile file to deploy the change. This can be done by:

The SML installation is now complete and you can test it by typing ‘sml’ in your terminal. If you get the following message, your SML works and you can get started with it.

Screenshot of SML

Screenshot of SML

 

SML on Sublime Text

Sublime Text has off late been my text editor of choice and using SML on Sublime Text makes things quite easy. If you have Package Control installed on Sublime Text already you can skip ahead to step 2.

  1. Install Package Control for Sublime Text. Follow the instructions provided at https://sublime.wbond.net/installation.
  2. Install SublimeREPL
    • Bring up the ST command palette by Tools > Command Palette (or Command+Shift+P).
    • Type Install Package in the prompt that comes up and select “Package Control: Install Package”.
    • In the second prompt that comes up type SublimeREPL and press enter to install Sublime REPL.
  3. Install Standard ML language definition in Sublime Text
    • Bring up the ST command palette by Tools > Command Palette (or Command+Shift+P).
    • Type Install Package in the prompt that comes up and select “Package Control: Install Package”.
    • In the second prompt type “Standard ML” and press enter.
  4. Go Sublime Text > Preferences > Browse Packages
  5. Browse to the Packages/User folder and create a folder called SML and place the “Default.sublime-commands” and “Main.sublime-menu” files available at https://gist.github.com/carlh/4507534. Modify the first item in the cmd list to the SML executable which in our case is /usr/local/smlnj/bin/sml
  6. Restart Sublime Text to have syntax highlighting available. The REPL can be accessed by Tools > SublimeREPL > SML

 

If you have a SML file open on ST while opening the REPL, the file will be passed to the REPL and executed.

If you open the REPL from an empty document, you will get the following message. However, SML would have loaded and you can type your code there.

If you open the REPL from any other type of file, you will get an error saying

Leave a Reply

Your email address will not be published. Required fields are marked *