Mercury (programming language)

This is an old revision of this page, as edited by Qwertyus (talk | contribs) at 19:08, 6 March 2006 (links). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Mercury is a functional logic programming language geared towards real-world applications. The first version was developed by Fergus Henderson, Thomas Conway and Zoltan Somogyi and was released on April 8th, 1995. The latest official release was version 0.12.2, released on the 25th January, 2006.

Mercury has several features intended for better software engineering. It is compiled rather than interpreted, as is traditional for logic programming languages. It features a sophisticated, strict type and mode system. Its authors claim these features combined with logic programming's abstract nature speeds writing of reliable programs. Mercury's module system enables division into self-contained units, a problem for past logic programming languages. (But note that several existing Prolog implementations also include module systems.)

Mercury is a more "pure", and therefore more declarative, language than Prolog, since it does not have "extra-logical" Prolog features like the "cut" (a Prolog construct which prevents backtracking) and imperative I/O. This makes the coding of sequential algorithms somewhat more cumbersome, but it makes automated program optimization easier. This means that it can produce significantly faster code than Prolog.

Hello World in Mercury:

 :- module hello.
 :- interface.
 :- import_module io.
 :- pred main(io.state, io.state).
 :- mode main(di, uo) is det.

 :- implementation.
 main(!IO) :-
 	io.write_string("Hello, World!\n", !IO).

(adapted from Ralph Becket's Mercury tutorial).

Mercury is developed at the University Of Melbourne Computer Science department under the supervision of Zoltan Somogyi.

Mercury has several back-ends, including low-level C for GCC (the original Mercury back-end), high-level C, IL for Microsoft's .NET, Java for Sun's JVM, and assembler via the GCC back-end (the last three are only considered alpha or beta quality). Mercury has also been used to target Aditi, a deductive database system also developed at the University of Melbourne. This makes it useful for targeting multiple platforms, or linking with code written in multiple back-ends. Mercury has a strong foreign language interface, including the ability to write in C for both C backends, in IL, C# or Managed C++ for the IL backend, and in Java for the Java backend. However, this means that foreign language code may need to be written several times for the different backends, otherwise portability between backends will be lost.

Mercury is available for most Unix platforms, for Mac OS X, and for Microsoft Windows using the Cygwin or MinGW toolsets (though it can also be compiled with Microsoft Visual C).

Notable programs written in Mercury include the Mercury compiler itself and the Prince XML formatter.