ML (programming language)

[1] ML provides pattern matching for function arguments, garbage collection, imperative programming, call-by-value and currying.

ML was developed by Robin Milner and others in the early 1970s at the University of Edinburgh,[4] and its syntax is inspired by ISWIM.

Ideas from ML have influenced numerous other languages, like Haskell, Cyclone, Nemerle,[5] ATS, and Elm.

Rewritten without the type annotations, the example looks like: The function also relies on pattern matching, an important part of ML programming.

This implementation of the factorial function is not guaranteed to terminate, since a negative argument causes an infinite descending chain of recursive calls.

A more robust implementation would check for a nonnegative argument before recursing, as follows: The problematic case (when n is negative) demonstrates a use of ML's exception system.

This implementation of reverse, while correct and clear, is inefficient, requiring quadratic time for execution.

For example, the following define an Arithmetic signature and an implementation of it using Rational numbers: These are imported into the interpreter by the 'use' command.

Interaction with the implementation is only allowed via the signature functions, for example it is not possible to create a 'Rat' data object directly via this code.