Paradigm | Logic, functional, object-oriented |
---|---|
Designed by | Zoltan Somogyi |
Developer | University of Melbourne |
First appeared | 1995 |
Stable release |
14.01.1 / September 8, 2014
|
Typing discipline | Strong, static, polymorphic |
OS | Cross-platform (Unix, Mac OS X, Windows) |
License | GPL for compiler, LGPL for standard library |
Filename extensions | .m |
Website | www |
Major implementations | |
Melbourne Mercury Compiler | |
Influenced by | |
Prolog, Hope, Haskell |
Mercury is a functional logic programming language geared towards real-world applications. It was initially 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. 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.
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 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 strict static type and mode system and a module system.
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. Its 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 static analysis and program optimization, including compile-time garbage collection, but can make certain programming constructs (such as a switch over a number of options, with a default) harder to express. (Note that while Mercury does allow impure functionality, this serves primarily as a way of calling foreign language code. 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.