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 20250523, MLton includes a port of the SML/NJ Library synchronized with SML/NJ version 110.99.8.
Usage
-
You can import a sub-library of the SML/NJ Library into an MLB file with:
MLB file Description $(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlbVarious utility modules, included collections, simple formating, …
$(SML_LIB)/smlnj-lib/Controls/controls-lib.mlbA library for managing control flags in an application.
$(SML_LIB)/smlnj-lib/HashCons/hash-cons-lib.mlbSupport for implementing hash-consed data structures.
$(SML_LIB)/smlnj-lib/HTML/html-lib.mlbHTML 3.2 parsing and pretty-printing library.
$(SML_LIB)/smlnj-lib/HTML4/html4-lib.mlbHTML 4.01 parsing and pretty-printing library.
$(SML_LIB)/smlnj-lib/INet/inet-lib.mlbNetworking utilities; supported on both Unix and Windows systems.
$(SML_LIB)/smlnj-lib/JSON/json-lib.mlbJavaScript Object Notation (JSON) reading and writing library.
$(SML_LIB)/smlnj-lib/PP/pp-lib.mlbPretty-printing library.
$(SML_LIB)/smlnj-lib/Reactive/reactive-lib.mlbReactive scripting library.
$(SML_LIB)/smlnj-lib/RegExp/regexp-lib.mlbRegular expression library.
$(SML_LIB)/smlnj-lib/SExp/sexp-lib.mlbS-expression library.
$(SML_LIB)/smlnj-lib/Unix/unix-lib.mlbUtilities for Unix-based operating systems.
$(SML_LIB)/smlnj-lib/UUID/uuid-lib.mlbUUID generating library.
$(SML_LIB)/smlnj-lib/XML/xml-lib.mlbXML 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 $smlnj-lib.cm $(SML_LIB)/smlnj-lib/Util $controls-lib.cm $(SML_LIB)/smlnj-lib/Controls $hash-cons-lib.cm $(SML_LIB)/smlnj-lib/HashCons $html-lib.cm $(SML_LIB)/smlnj-lib/HTML $html4-lib.cm $(SML_LIB)/smlnj-lib/HTML4 $inet-lib.cm $(SML_LIB)/smlnj-lib/INet $json-lib.cm $(SML_LIB)/smlnj-lib/JSON $pp-lib.cm $(SML_LIB)/smlnj-lib/PP $reactive-lib.cm $(SML_LIB)/smlnj-lib/Reactive $regexp-lib.cm $(SML_LIB)/smlnj-lib/RegExp $sexp-lib.cm $(SML_LIB)/smlnj-lib/SExp $unix-lib.cm $(SML_LIB)/smlnj-lib/Unix $xml-lib.cm $(SML_LIB)/smlnj-lib/XML
This will automatically convert a
$/smlnj-lib.cmimport in an input.cmfile into a$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlbimport in the output.mlbfile.
Details
The following changes were made to the SML/NJ Library, in addition to
deriving the .mlb files from the .cm files:
-
Compat/either(added): Implementssignature EITHERandstructure Either: EITHER(see https://github.com/SMLFamily/BasisLibrary/wiki/2015-002-Addition-of-Either-module); used by RegExp Library. -
Compat/fn(added): Implementssignature FNandstructure Fn: FN(see https://github.com/SMLFamily/BasisLibrary/wiki/2015-005-Addition-of-Fn-module); used by JSON Library. -
Compat/mono-buffer(added): Implementssignature MONO_BUFFERandstructure CharBuffer: MONO_BUFFER(see https://github.com/SMLFamily/BasisLibrary/wiki/2018-001-Addition-of-monomorphic-buffers); used by JSON and PP Libraries. -
Compat/mono-sequence(added): Implementssignature MONO_{ARRAY,VECTOR}{,_SLICE}_EXTandstructure Word8Slice: MONO_VECTOR_SLICE_EXT(see https://github.com/SMLFamily/BasisLibrary/wiki/2015-003-Additional-operations-on-sequences and https://github.com/SMLFamily/BasisLibrary/wiki/2018-001-Addition-of-monomorphic-buffers); used by SML/NJ Library. -
HTML4/pp-init.sml(added): Implementsstructure PrettyPrintusing the SML/NJ PP Library. This implementation is taken from the SML/NJ compiler source, since the SML/NJ HTML4 Library used thestructure PrettyPrintprovided by the SML/NJ compiler itself. -
JSON/json-stream-parser.smlandJSON/json-parser.sml(modified): Rewrote use ofUnsafe.CharVector.createandUnsafe.CharVector.update; MLton assumes that vectors are immutable. -
Util/base64.sml(modified): Rewrote use ofUnsafe.CharVector.createandUnsafe.CharVector.update; MLton assumes that vectors are immutable. -
Util/dynamic-array.sml(modified): Rewrote use ofArray.fromVector. -
Util/engine.mlton.sml(added, not exported): Implementsstructure Engine, providing time-limited, resumable computations using <:MLtonThread:>, <:MLtonSignal:>, and <:MLtonItimer:>. -
Util/graph-scc-fn.sml(modified): Rewrote use ofwherestructure specification. -
Util/time-limit.mlb(added): Exportsstructure TimeLimit, which is not exported bysmlnj-lib.mlb. Since MLton is very conservative in the presence of threads and signals, program performance may be adversely affected by unnecessarily includingstructure TimeLimit. -
Util/time-limit.mlton.sml(added): Implementsstructure TimeLimitusingstructure Engine. The SML/NJ implementation ofstructure TimeLimituses SML/NJ’s first-class continuations, signals, and interval timer. -
Util/utf8.sml(modified): Rewrote use ofString.implodeRev(see https://github.com/SMLFamily/BasisLibrary/wiki/2015-003d-STRING).