Standard ML (SML) belongs to the ML family of programming languages. Like other members of this family (such as OCaml), it is characterized by strong, static typing, strict evaluation, and type inference. The current standard dates from 1997; it supersedes an earlier standard from 1990.

The following code snippet creates a function factorial that accepts a non-negative integer n and returns its factorial.

fun factorial n =
if n < 1
then 1
else n * factorial (n - 1);

The following code snippet creates a function gray_code that accepts an integer n, and returns a list of all distinct n-character strings of 0s and 1s, in Gray code order (such that any two successive elements of the list differ in exactly one character). It then uses this function to generate the list gray_code_3 equal to ["000", "001", "011", "010", "110", "111", "101", "100"].

To get started with Standard ML, one needs a compiler. Most compilers compile directly to machine code; however, unlike (for example) a typical C compiler, several SML compilers, such as Standard ML of New Jersey (SMLNJ), can accept SML input interactively, compiling and evaluating code as it is entered. This can be very convenient when first getting started with SML. One important note: the code snippets in this book are presented in the form they would take in a normal SML program that is first saved as a file. To run them interactively in SMLNJ, a semicolon should be appended, to inform SMLNJ that it can evaluate the code so far; for example, the factorial example above would be written thus: