next up previous contents
Next: Drawbacks of MLton Up: MLton User Guide Previous: Hello, World!   Contents


Features of MLton

whole-program optimization

Because MLton compiles the whole program at once, it can perform optimization across module boundaries. As a consequence, MLton can reduce or eliminate the runtime penalty that arises with separate compilation of SML features such as functors, modules, polymorphism, and higher-order functions. MLton takes advantage of having the entire program to perform transformations such as: defunctorization, monomorphisation, higher-order control-flow analysis, inlining, unboxing, argument flattening, redundant-argument removal, constant folding, and representation selection. Whole program compilation is an integral part of the design of MLton and is not likely to change.

SML 97 compliant

MLton compiles the full Standard ML language as given in The Definition of Standard ML (Revised)[MTHM97]. If there is a program that is valid according to The Definition that is rejected by MLton, it is a bug.

basis library mostly complete

MLton contains a mostly complete implementation of the basis library. Missing are some IO modules (BinIO, ImperativeIO, StreamIO, PrimIO), and a few functions in the IntInf, Os.IO, Real, and TextIO structures. See Section 7 for details.

good run-time performance

MLton generated executables have good run-time performance. For a comparison of several SML compilers, see http://www.sourcelight.com/MLton/performance.html. For a comparison of many compilers, including MLton, see http://www.bagley.org/~doug/shootout/.

standalone executables

MLton generates standalone executables. No additional code or libraries are necessary in order to run an executable. MLton can also generate statically linked executables.

small executables

Because of whole-program compilation, MLton can use very aggressive dead-code elimination, which often leads to smaller executables than with other compilers.

compiles large programs

MLton is sufficiently robust that it can compile large programs, including itself (83K lines) and the ML Kit Version 3 (75K lines). The distributed version of MLton was compiled by MLton.

fast IntInf based on GNU multiprecision library

The MLton implementation of arbitrary precision arithmetic (the IntInf structure) uses the GNU multiprecision library (gmp). Hence, for IntInf intensive programs, MLton is often orders of magnitude faster than SML/NJ.

fast C FFI

MLton has a straightforward and fast FFI for calling C routines from SML. In fact, much of the Posix structure in the basis library is implemented using the C FFI. The FFI also supports the definition of compile-time constants. See Section 5 for details.

profiling

MLton has support for profiling similar to gprof. See Section 6 for details.

useful libraries

MLton has a collection of libraries that provide useful functionality that cannot be implemented with the standard basis library. See below for an overview and Section 8 for details.

size primitive

MLton includes a primitive that returns the size (in bytes) of any object. This can be quite useful in understanding the space behavior of a program.

continuations

MLton supports continuations via callcc and throw.

interval timers

MLton supports the functionality of the C setitimer function.

random numbers

MLton has functions similar to the C rand and srand functions, as well as support for access to /dev/random and /dev/urandom.

resource usage

MLton supports a subset of the functionality of the C getrusage function.

signal handlers

MLton supports signal handlers written in SML. Signal handlers are run in a separate thread, and have access to the thread that was interrupted by the signal. Signal handlers can be used in conjunction with threads to implement preemptive multitasking.

sockets

MLton supports simple socket operations like accept, connect, and listen.

system logging

MLton has a complete interface to the C syslog function.

threads

MLton has preliminary support for threads, upon which either preemptive or non-preemptive multitasking can be implemented. Threads are still experimental. At some point in the future, MLton may support CML, but there is still a ways to go.

world save and restore

MLton has a facility for saving the entire state of a computation to a file, and restarting it later. This facility can be used for staging and for checkpointing computations. It can even be used from within signal handlers, allowing interrupt driven checkpointing.


next up previous contents
Next: Drawbacks of MLton Up: MLton User Guide Previous: Hello, World!   Contents