Mercury programming language

From Free net encyclopedia

Mercury is a functional logic programming language geared towards real-world applications. It is developed at the University Of Melbourne Computer Science department under the supervision of Zoltan Somogyi. 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. Several Prolog implementations now support modules.

Mercury is a more pure, thus more declarative, than Prolog, since it lacks "extra-logical" Prolog statements such as "cut" (which prevents backtracking) and imperative I/O. This enables better program optimization, but makes coding sequential algorithms harder. Due to the optimizations enabled by the purity of the lanague, programs written in Mercury typically perform significantly faster than equivilent programs written in Prolog.

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

The Mercury compiler is implemented in Mercury itself, and so is the Prince XML formatter.

Back-ends

Mercury has several back-ends, which means it is possible to compile Mercury code into the following languages:

(the last three are 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, allowing code in other languages (depending on the chosen back-end) to be linked with Mercury code. The following foreign languages are possible:

Back-end Foreign language(s)
C (both levels) C
IL IL, C# or [[Managed Extensions for C++|Managed C++]]
Java Java

Other languages can be interfaced to by calling them from these languages. 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.

Examples

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).

External links

it:Mercury (linguaggio) ru:Mercury (язык программирования)