All Topics  
ML programming language

 

   Email Print
   Bookmark   Link






 

ML programming language



 
 
ML is a general-purpose functional programming language developed by Robin Milner
Robin Milner

Arthur John Robin Gorell Milner Fellow of the Royal Society FRSE is a prominent British computer scientist....
 and others in the late 1970s at the University of Edinburgh
University of Edinburgh

The University of Edinburgh founded in 1582, is an internationally renowned centre for teaching and research in Edinburgh, Scotland, United Kingdom....
, whose syntax is inspired by ISWIM
ISWIM

ISWIM is an abstract computer programming language devised by Peter J. Landin and first described in his article, The Next 700 Programming Languages, published in the Communications of the ACM in 1966....
. Historically, ML stands for metalanguage: it was conceived to develop proof tactics in the LCF theorem prover
LCF theorem prover

LCF is an interactive automated theorem prover developed at the universities of University of Edinburgh and Stanford University by Robin Milner and others....
 (whose language, pplambda, a combination of the first-order predicate calculus and the simply-typed polymorphic lambda-calculus, had ML as its metalanguage).






Discussion
Ask a question about 'ML programming language'
Start a new discussion about 'ML programming language'
Answer questions from other users
Full Discussion Forum



Recent Posts









Encyclopedia


ML is a general-purpose functional programming language developed by Robin Milner
Robin Milner

Arthur John Robin Gorell Milner Fellow of the Royal Society FRSE is a prominent British computer scientist....
 and others in the late 1970s at the University of Edinburgh
University of Edinburgh

The University of Edinburgh founded in 1582, is an internationally renowned centre for teaching and research in Edinburgh, Scotland, United Kingdom....
, whose syntax is inspired by ISWIM
ISWIM

ISWIM is an abstract computer programming language devised by Peter J. Landin and first described in his article, The Next 700 Programming Languages, published in the Communications of the ACM in 1966....
. Historically, ML stands for metalanguage: it was conceived to develop proof tactics in the LCF theorem prover
LCF theorem prover

LCF is an interactive automated theorem prover developed at the universities of University of Edinburgh and Stanford University by Robin Milner and others....
 (whose language, pplambda, a combination of the first-order predicate calculus and the simply-typed polymorphic lambda-calculus, had ML as its metalanguage). It is known for its use of the Hindley-Milner type inference algorithm, which can automatically infer the types
Data type

A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it....
 of most expressions
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
 without requiring explicit type annotations.

Overview

ML is often referred to as an impure functional language, because it permits side-effects, and therefore imperative programming
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
, unlike purely functional
Purely functional

Purely functional is a term in computing used to describe algorithms, data structures or programming languages that exclude destructive modifications ....
 programming languages such as Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
. For this reason it's also called a Multi-paradigm programming language
Multi-paradigm programming language

A multi-paradigm programming language is a programming language that supports more than one programming paradigm. As Lead designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in a variety of styles, freely intermixing constructs from different paradigms. The design goal...
.

Features of ML include a call-by-value evaluation strategy
Evaluation strategy

In computer science, an evaluation strategy is a set of rules for determining the evaluation of expression in a programming language. Emphasis is typically placed on subprogram or operators ? an evaluation strategy defines when and in what order the arguments to a function are evaluated, when they are substituted into the function, and wha...
, first class functions, automatic memory management through garbage collection
Garbage collection (computer science)

In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software....
, parametric polymorphism, static typing, type inference
Type inference

Type inference, or implicit typing, refers to the ability to deduce automatically the type of a value in a programming language. It is a feature present in some strongly-typed programming language static typing#Static and dynamic typing languages....
, algebraic data types, pattern matching
Pattern matching

In computer science, pattern matching is the act of checking for the presence of the constituents of a given pattern. In contrast to pattern recognition, the pattern is rigidly specified....
, and exception handling
Exception handling

Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution....
.

Unlike Haskell, ML uses eager evaluation
Eager evaluation

Eager evaluation or strict evaluation is the evaluation strategy in most traditional programming languages.In eager evaluation an Expression is evaluated as soon as it gets bound to a variable....
, which means that all subexpressions are always evaluated. However, lazy evaluation can be achieved through the use of closures. Thus one can create and use infinite streams as in Haskell, however, their expression is comparatively indirect.

Today there are several languages in the ML family; the two major dialects are Standard ML
Standard ML

Standard ML is a general-purpose, Module , functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of automated theorem proving....
 (SML) and Caml
CAML

CAML may mean:* Caml, a dialect of the ML programming language* Collaborative Application Markup Language, an XML-based markup language used with the Microsoft SharePoint collaborative portal application...
, but others exist, including F#
F Sharp programming language

F# is a multi-paradigm programming language, targeting the .NET Framework, that encompasses functional programming as well as imperative programming object-oriented programming disciplines....
 - an open research project that targets the Microsoft .NET platform. Ideas from ML have influenced numerous other languages, like Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
, Cyclone
Cyclone programming language

The Cyclone programming language is intended to be a safe dialect of the C . Cyclone is designed to avoid buffer overflows and other vulnerabilities that are endemic in C programs, without losing the power and convenience of C as a tool for systems programming....
, and Nemerle
Nemerle

Nemerle is a high level language static typing programming language for the Microsoft .NET platform. It offers functional programming, object-oriented and imperative programming features....
.

ML's strengths are mostly applied in language design and manipulation (compilers, analyzers, theorem provers), but it is a general-purpose language also used in bioinformatics, financial systems, and applications including a genealogical database, a peer-to-peer client/server program, etc.

ML uses static scoping rules.

Examples of ML


Anatomy of an ML function

The "Hello World"
Hello world program

A "Hello World" program is a computer program that prints out "Hello world!" on a display device. It is used in many introductory tutorials for teaching a programming language....
 of functional languages is the factorial
Factorial

In mathematics, the factorial of a negative and non-negative numbers integer n, denoted by n!, is the Product of all positive integers less than or equal to n....
 function. Expressed as pure ML:

fun fac (0 : int) : int = 1 | fac (n : int) : int = n * fac (n-1)

This describes the factorial as a recursive function, with a single terminating base case. It is similar to the descriptions of factorials found in mathematics textbooks. Much of ML code is similar to mathematics in facility and syntax.

Part of the definition shown is optional, and describes the types of this function. The notation E : t can be read as expression E has type t. For instance, the argument n is assigned type integer (int), and the result of applying fac to n (fac (n)) also has type integer. The function fac as a whole then has type function from integer to integer (int -> int). Thanks to type inference
Type inference

Type inference, or implicit typing, refers to the ability to deduce automatically the type of a value in a programming language. It is a feature present in some strongly-typed programming language static typing#Static and dynamic typing languages....
, the type annotations can be omitted and will be derived by the compiler. Rewritten without the type annotations, the example looks like:

fun fac 0 = 1 | fac n = n * fac (n-1)

The function also relies on pattern matching
Pattern matching

In computer science, pattern matching is the act of checking for the presence of the constituents of a given pattern. In contrast to pattern recognition, the pattern is rigidly specified....
, an important part of ML programming. Note that parameters of a function are not necessarily in parentheses but separated by spaces. When the function's argument is 0 (zero) it will return the integer 1 (one). For all other cases the second line is tried. This is the recursion
Recursion

Recursion, in mathematics and computer science, is a method of defining Function in which the function being defined is applied within its own definition....
, and executes the function again until the base case is reached.

Reverse Function:

fun reverse ls = let fun reverseInner nil acc = acc | reverseInner (hdtail) acc = reverseInner tail (hdacc) in reverseInner ls nil end

See also

  • LCF theorem prover
    LCF theorem prover

    LCF is an interactive automated theorem prover developed at the universities of University of Edinburgh and Stanford University by Robin Milner and others....
  • ISWIM
    ISWIM

    ISWIM is an abstract computer programming language devised by Peter J. Landin and first described in his article, The Next 700 Programming Languages, published in the Communications of the ACM in 1966....
  • F#
    F Sharp programming language

    F# is a multi-paradigm programming language, targeting the .NET Framework, that encompasses functional programming as well as imperative programming object-oriented programming disciplines....
  • Haskell
    Haskell (programming language)

    Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
  • Cyclone
    Cyclone programming language

    The Cyclone programming language is intended to be a safe dialect of the C . Cyclone is designed to avoid buffer overflows and other vulnerabilities that are endemic in C programs, without losing the power and convenience of C as a tool for systems programming....
  • Nemerle
    Nemerle

    Nemerle is a high level language static typing programming language for the Microsoft .NET platform. It offers functional programming, object-oriented and imperative programming features....


Dialects

  • Caml
    CAML

    CAML may mean:* Caml, a dialect of the ML programming language* Collaborative Application Markup Language, an XML-based markup language used with the Microsoft SharePoint collaborative portal application...
    , a dialect of ML, which became...
  • Objective Caml
    Objective Caml

    Objective Caml, or OCaml is the main implementation of the Caml programming language, created by Xavier Leroy, J?r?me Vouillon, Damien Doligez, Didier R?my and others in 1996....
    , the famous dialect of Caml with support for object-oriented programming


  • Standard ML
    Standard ML

    Standard ML is a general-purpose, Module , functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of automated theorem proving....
    , a dialect of ML with a formal semantics
  • Alice (programming language)
    Alice (programming language)

    Alice is a functional programming language designed by the at Saarland University. It is a dialect of Standard ML, augmented with support for lazy evaluation, Concurrency and constraint programming....
  • F#
  • Rpal
    Rpal

    Rpal is a functional programming language which is related to the ML programming language.RPAL is an acronym meaning Right Reference - Pedagogic Algorithmic Language ....
  • LML (Lazy ML)
    Lazy ML

    Lazy ML is a functional programming language developed in the early 1980s by Lennart Augustsson and Thomas Johnsson at Chalmers University of Technology, prior to Miranda programming language and Haskell ....


Books

  • The Definition of Standard ML, Robin Milner, Mads Tofte, Robert Harper, MIT Press 1990
  • The Definition of Standard ML (Revised), Robin Milner, Mads Tofte, Robert Harper, David MacQueen, MIT Press 1997. ISBN 0-262-63181-4
  • Commentary on Standard ML, Robin Milner, Mads Tofte, MIT Press 1997. ISBN 0-262-63137-7


External links