Mercury (programming language)
From Seo Wiki - Search Engine Optimization and Programming Languages
|Designed by||Zoltán Somogyi|
|Developer||University of Melbourne|
|Stable release||0.13.1 (1 December 2006)|
|Preview release||Release of the day (daily)|
|Typing discipline||Strong, static, polymorphic|
|Major implementations||Melbourne Mercury Compiler|
|Influenced by||Prolog, Haskell|
|License||GPL for compiler, LGPL for standard library|
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 Zoltán Somogyi. The first version was developed by Fergus Henderson, Thomas Conway and Zoltán Somogyi and was released on April 8, 1995.
The official implementation, the Melbourne Mercury Compiler is available for most Unix platforms, including Mac OS X, and Microsoft Windows (in Windows, it requires one of the Cygwin or MinGW toolsets, and can be compiled either with GCC or Microsoft Visual C++).
Although having no "stable" releases since 2006, Mercury is still under active development as of 2010. A new snapshot release is made automatically each day which has more features and, usually, fewer bugs than the "stable" release.
Mercury is based on the logic programming language Prolog. It has the same syntax, and the same basic concepts such as the SLD resolution algorithm. It can ostensibly be viewed as a pure subset of Prolog with strong types and modes. As such, it is often compared to its predecessor, both in terms of features, and run-time efficiency.
The language is designed with software engineering principles in mind.[neutrality is disputed] Unlike Prolog, it has a separate compilation phase, rather than being directly interpreted, which allows a much wider range of errors to be caught before running a program. (Modern versions of Prolog normally support compilation as well as providing an interpreter. An executable produced by a modern Prolog compiler can also be very efficient.) It features a sophisticated, strict type and mode system, which its authors claim makes it much easier to write robust software. Mercury's module system enables division into self-contained units, a problem for past logic programming languages. (But note that several Prolog implementations now also support modules.)
Due to the use of information obtained at compile time (such as type and mode information), programs written in Mercury typically perform significantly faster than equivalent programs written in Prolog. The authors claim that Mercury is the fastest logic language in the world, by a wide margin.
Mercury is a purely declarative language, unlike Prolog, since it lacks "extra-logical" Prolog statements such as "cut" and imperative I/O. This enables advanced program optimization, but can make certain programming constructs (such as a switch over a number of options, with a default[dubious ]) harder to express. (Note that while Mercury does allow impure functionality, it is not necessary in most software, and serves primarily as a way of calling foreign language code. Also, all impure code must be explicitly marked.)
Notable programs written in Mercury include the Mercury compiler itself and the Prince XML formatter. Mission Critical IT, a software company, has also used Mercury since 2000 to develop enterprise applications.
Mercury has several back-ends, which means it is possible to compile Mercury code into the following languages and code-styles:
Dormant (may not work well, or even be completely broken):
- Aditi, a deductive database system also developed at the University of Melbourne. Mercury-0.12.2 is the last version of Mercury that will support Aditi.
This makes Mercury a useful high-level language for targeting multiple platforms, or for linking with code written using multiple back-ends.
Mercury also 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:
|C (both levels)||C|
|IL||IL or C#|
Other languages can then 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.
The most commonly used back-end is the original low-level C back-end. As both C backends are the only back-ends considered production quality, this means that you will not lose a great deal of portability using foreign-language C code.
:- module hello. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. :- implementation. main(!IO) :- io.write_string("Hello, World!\n", !IO).
:- module fib. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. :- implementation. :- import_module int. :-func fib(int) = int. fib(N) = (if N =< 2 then 1 else fib(N - 1) + fib(N - 2)). main(!IO) :- io.write_string("fib(10) = ", !IO), io.write_int(fib(10), !IO), io.nl(!IO). % Could instead use io.format("fib(10) = %d\n", [i(fib(10))], !IO).
- ↑ 1.0 1.1 1.2 The Mercury Project - Motivation
- ↑ mercury-developers mailing list, January 2010
- ↑ The Mercury Project - Benchmarks
- ↑ Somogyi, Zoltan; Henderson, Fergus and Conway, Thomas (October-December 1996). "The execution algorithm of Mercury: an efficient purely declarative logic programming language". Journal of Logic Programming 29 (1-3): 17–64. doi:10.1016/S0743-1066(96)00068-4. http://www.mercury.csse.unimelb.edu.au/information/papers.html#jlp. Retrieved 2008-08-30.
- ↑ Adapted from Ralph Becket's Mercury tutorial
- Alice programming language
- Oz/Mozart programming language and compiler
- Visual Prolog programming language
- Official Mercury Homepage
- Literate Programs (examples) in Mercury
- Papers And Presentations About Mercuryca:Mercury