The SML/NJ Library is a collection of libraries that are distributed with SML/NJ. Due to differences between SML/NJ and MLton, these libraries will not work out-of-the box with MLton.

As of 20180119, MLton includes a port of the SML/NJ Library synchronized with SML/NJ version 110.82.


  • You can import a sub-library of the SML/NJ Library into an MLB file with:

    MLB file Description


    Various utility modules, included collections, simple formating, …


    A library for managing control flags in an application.


    Support for implementing hash-consed data structures.


    HTML 3.2 parsing and pretty-printing library.


    HTML 4.01 parsing and pretty-printing library.


    Networking utilities; supported on both Unix and Windows systems.


    JavaScript Object Notation (JSON) reading and writing library.


    Pretty-printing library.


    Reactive scripting library.


    Regular expression library.


    S-expression library.


    Utilities for Unix-based operating systems.


    XML library.

  • If you are porting a project from SML/NJ’s CompilationManager to MLton’s ML Basis system using cm2mlb, note that the following maps are included by default:

    # SMLNJ Library
    $SMLNJ-LIB                              $(SML_LIB)/smlnj-lib
    $                           $(SML_LIB)/smlnj-lib/Util
    $                        $(SML_LIB)/smlnj-lib/Controls
    $                       $(SML_LIB)/smlnj-lib/HashCons
    $                            $(SML_LIB)/smlnj-lib/HTML
    $                           $(SML_LIB)/smlnj-lib/HTML4
    $                            $(SML_LIB)/smlnj-lib/INet
    $                            $(SML_LIB)/smlnj-lib/JSON
    $                              $(SML_LIB)/smlnj-lib/PP
    $                        $(SML_LIB)/smlnj-lib/Reactive
    $                          $(SML_LIB)/smlnj-lib/RegExp
    $                            $(SML_LIB)/smlnj-lib/SExp
    $                            $(SML_LIB)/smlnj-lib/Unix
    $                             $(SML_LIB)/smlnj-lib/XML

    This will automatically convert a $/ import in an input .cm file into a $(SML_LIB)/smlnj-lib/Util/ import in the output .mlb file.


The following changes were made to the SML/NJ Library, in addition to deriving the .mlb files from the .cm files:

  • HTML4/pp-init.sml (added): Implements structure PrettyPrint using the SML/NJ PP Library. This implementation is taken from the SML/NJ compiler source, since the SML/NJ HTML4 Library used the structure PrettyPrint provided by the SML/NJ compiler itself.

  • Util/base64.sml (modified): Rewrote use of Unsafe.CharVector.create and Unsafe.CharVector.update; MLton assumes that vectors are immutable.

  • Util/engine.mlton.sml (added, not exported): Implements structure Engine, providing time-limited, resumable computations using MLtonThread, MLtonSignal, and MLtonItimer.

  • Util/graph-scc-fn.sml (modified): Rewrote use of where structure specification.

  • Util/redblack-map-fn.sml (modified): Rewrote use of where structure specification.

  • Util/redblack-set-fn.sml (modified): Rewrote use of where structure specification.

  • Util/ (added): Exports structure TimeLimit, which is not exported by Since MLton is very conservative in the presence of threads and signals, program performance may be adversely affected by unnecessarily including structure TimeLimit.

  • Util/time-limit.mlton.sml (added): Implements structure TimeLimit using structure Engine. The SML/NJ implementation of structure TimeLimit uses SML/NJ’s first-class continuations, signals, and interval timer.