Mercury (programming language)


Mercury (programming language)
Mercury
Mercury logo.jpg
Paradigm(s) Logic, functional
Appeared in 1995
Designed by Zoltán Somogyi
Developer University of Melbourne
Stable release 11.01 (27 April 2011)
Typing discipline Strong, static, polymorphic
Major implementations Melbourne Mercury Compiler
Influenced by Prolog, Haskell
OS Cross-platform (Unix, Mac OS X, Windows)
License GPL for compiler, LGPL for standard library
Website mercury.csse.unimelb.edu.au

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 8, 1995.

Mercury is a purely declarative logic language. It is related to both Prolog and Haskell.[1] It features a strong, static, polymorphic type system, as well as a strong mode and determinism system.

The official implementation, the Melbourne Mercury Compiler, is available for most Unix platforms, including Mac OS X, as well as for Microsoft Windows (in Windows, it requires one of the Cygwin or MinGW toolsets, and can be compiled either with GCC or Microsoft Visual C++).

Contents

Overview

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. Unlike the original implementations of 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. It features a sophisticated, strict type and mode system, which its authors claim makes it much easier to write robust software.[1] Mercury's module system enables division into self-contained units, a problem for past logic programming languages.

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.[2][3] The authors claim that Mercury is the fastest logic language in the world, by a wide margin.[1]

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

Operations which would typically be impure (such as input/output) are expressed using pure constructs in Mercury using linear types, by threading a dummy "world" value through all relevant code.

Notable programs written in Mercury include the Mercury compiler itself and the Prince XML formatter. Mission Critical IT [1], a software company, has also been using Mercury since 2000 to develop enterprise applications.

Back-ends

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

Production level:

  • Low-level C for GCC (the original Mercury back-end)
  • High-level C
  • Java bytecode for the JVM

Beta quality:

Alpha quality (may not work well, or even be completely broken):

Past back-ends:

  • 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:

Back-end Foreign language(s)
C (both levels) C
Java Java
Erlang Erlang
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 considered production quality, this means that you will not lose a great deal of portability using foreign-language C code.

Examples

Hello World:

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

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

Calculating the 10th Fibonacci number (in the most obvious way)[4]:

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

Release schedule

The Mercury project has a new 6 monthly release cycle. Releases are named according to the year and month of the release. The current release is 11.01 (April 2011). Previously releases were numbered 0.12, 0.13, etc. and the period between stable releases was very large (3 years).

The Mercury project also makes a snapshot release daily. The snapshot release is the latest development snapshot of the system and has all the latest features and bug fixes added to the last stable release.

See also

References

  1. ^ a b c The Mercury Project - Motivation
  2. ^ The Mercury Project - Benchmarks
  3. ^ 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. 
  4. ^ Adapted from Ralph Becket's Mercury tutorial

External links


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Haskell (programming language) — Haskell Paradigm(s) functional, lazy/non strict, modular Appeared in 1990 Designed by Simon Peyton Jones, Lennart Aug …   Wikipedia

  • Oz (programming language) — Oz Paradigm(s) multi paradigm: logic, functional, imperative, object oriented, constraint, distributed, concurrent Appeared in 1991 Designed by Gert Smolka, his students Developer Mozart …   Wikipedia

  • F Sharp (programming language) — The correct title of this article is F#. The substitution or omission of the # sign is because of technical restrictions. F# Paradigm(s) multi paradigm: functional, imperative, object oriented Appeared in 2002 (2002) …   Wikipedia

  • Fifth-generation programming language — A fifth generation programming language (abbreviated 5GL) is a programming language based around solving problems using constraints given to the program, rather than using an algorithm written by a programmer. Most constraint based and logic… …   Wikipedia

  • Mercury — Contents 1 Geography 2 Populated places 3 Transportation 4 …   Wikipedia

  • List of functional programming topics — This is a list of functional programming topics. Contents 1 Foundational concepts 2 Lambda calculus 3 Combinatory logic 4 Intuitionistic logic …   Wikipedia

  • List of programming languages by category — Programming language lists Alphabetical Categorical Chronological Generational This is a list of programming languages grouped by category. Some languages are listed in multiple categories. Contents …   Wikipedia

  • List of programming languages — Programming language lists Alphabetical Categorical Chronological Generational The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and historical ones, in… …   Wikipedia

  • Logic programming — is, in its broadest sense, the use of mathematical logic for computer programming. In this view of logic programming, which can be traced at least as far back as John McCarthy s [1958] advice taker proposal, logic is used as a purely declarative… …   Wikipedia

  • Generational list of programming languages — Here, a genealogy of programming languages is shown. Languages are categorized under the ancestor language with the strongest influence. Of course, any such categorization has a large arbitrary element, since programming languages often… …   Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.