SMLtoJs (pronounced “SML toys”) compiles Standard ML to JavaScript for client-side web applications. It shares MLKit’s frontend and compilation management, bringing Standard ML’s static types, pattern matching, higher-order functions, and modules to browser programming.

Try the Online SML IDE »

The Online SML IDE runs the compiler in your browser: you can write, compile, and execute Standard ML without installing a compiler locally.

Language and browser support

SMLtoJs supports all of Standard ML and most of the Standard ML Basis Library. Browser integration includes calls to JavaScript functions, DOM access, and Standard ML functions used as event handlers and timer callbacks. Modules are eliminated at compile time, and optimizations include function inlining and specialization of higher-order functions.

Compile a program locally

Get SMLtoJs from the MLKit distribution or sources. Save the following as hello.sml:

val _ = print "Hello from Standard ML!\n"

Then compile it:

smltojs hello.sml

Open the generated run.html in a browser. Keep the generated JavaScript files alongside it. SMLtoJs also accepts an ML Basis file for programs split across several source files. Use smltojs -o hello hello.sml to name the generated page hello.html.

Further reading