Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Mercury (programming language)

From Wikipedia, the free encyclopedia
(Redirected fromMercury programming language)
Functional logic programming language
For Mercury Autocode, seeAutocode.
Not to be confused withMercurial orMercury (RemObjects BASIC programming language).
Mercury
ParadigmLogic,functional,object-oriented[citation needed]
FamilyProlog,Haskell
Designed byZoltan Somogyi
DeveloperUniversity of Melbourne
First appearedApril 8, 1995; 30 years ago (1995-04-08)
Stable release
22.01.8[1] Edit this on Wikidata / 8 September 2023; 2 years ago (8 September 2023)
Typing disciplinestrong,static,polymorphic
Scopelexical
Implementation languageMercury
PlatformIA-32,x86-64,ARM,SPARC64,Java,CLI
OSCross-platform:Unix,Linux,macOS,Solaris,FreeBSD,OpenBSD,Windows,Android
LicenseGPL compiler,
LGPL standard library
Filename extensions.m
Websitewww.mercurylang.org
Majorimplementations
Melbourne Mercury Compiler
Influenced by
Prolog,Hope,Haskell

Mercury is afunctional logic programming language made for real-world uses. The first version was developed at theUniversity of Melbourne, Computer Science department, by Fergus Henderson, Thomas Conway, and Zoltan Somogyi, under Somogyi's supervision, and released on April 8, 1995.

Mercury is a purelydeclarativelogic programming language. It is related to bothProlog andHaskell.[2] It features a strong, static, polymorphictype system, and a strong mode and determinism system.

The official implementation, the Melbourne Mercury Compiler, is available for mostUnix andUnix-like platforms, includingLinux,macOS, and forWindows.

Overview

[edit]

Mercury is based on the logic programming languageProlog. It has the same syntax and the same basic concepts such as theselective linear definite clause resolution (SLD) 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 in features and run-time efficiency.

The language is designed usingsoftware engineering principles. Unlike the original implementations of Prolog, it has a separatecompilation phase, rather than being directly interpreted. This allows a much wider range of errors to be detected before running a program. It features a strictstatic type and mode system[2] and a module system.

By using information obtained at compile time (such as type and mode), programs written in Mercury typically perform significantly faster than equivalent programs written in Prolog.[3][4] Its authors claim that Mercury is the fastest logic language in the world, by a wide margin.[2]

Mercury is a purelydeclarative language, unlikeProlog, since it lacksextra-logical Prolog statements such as! (cut) andimperativeinput/output (I/O). This enables advancedstatic program analysis andprogram optimization, including compile-timegarbage collection,[5] but it can make certain programming constructs (such as a switch over a number of options, with a default[dubiousdiscuss]) harder to express. While Mercury does allow impure functionality, it serves mainly as a way to call foreign language code. All impure code must be explicitly marked. Operations which would typically be impure (such asinput/output) are expressed using pure constructs in Mercury usinglinear types, by threading a dummyworld value through all relevant code.

Notable programs written in Mercury include the Mercury compiler and thePrince XML formatter. The Software company ODASE has also been using Mercury to develop its Ontology-Centric software development platform, ODASE.[6]

Back-ends

[edit]

Mercury has several back-ends, which enable compiling Mercury code into several languages, including:

Production level

[edit]

Past

[edit]

Mercury also features a 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-endForeign language(s)
C (both levels)C
JavaJava
ErlangErlang
ILCommon Intermediate Language (CIL) orC#

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.

Examples

[edit]

Hello World:

:-modulehello.:-interface.:-import_moduleio.:-predmain(io::di,io::uo)isdet.:-implementation.main(!IO):-io.write_string("Hello, World!\n",!IO).

Calculating the 10thFibonacci number (in the most obvious way):[7]

:-modulefib.:-interface.:-import_moduleio.:-predmain(io::di,io::uo)isdet.:-implementation.:-import_moduleint.:-funcfib(int)=int.fib(N)=(ifN=<2then1elsefib(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).

!IO is a "state variable", which issyntactic sugar for a pair of variables which are assigned concrete names at compilation; for example, the above is desugared to something like:

main(IO0,IO):-io.write_string("fib(10) = ",IO0,IO1),io.write_int(fib(10),IO1,IO2),io.nl(IO2,IO).

Release schedule

[edit]

The stable release naming scheme was 0.1 up to 0.13 for the first thirteen stable releases. In February 2010 the Mercury project decided to name each stable release by using the year and month of the release. For example 10.04 is for a release made in April 2010.

There is often also a periodic snapshot of the development systemrelease of the day (ROTD)

IDE and editor support

[edit]

See also

[edit]
  • Curry, another functional logic language
  • Alice, a dialect language ofStandard ML
  • Logtalk, language, an object-oriented extension of Prolog which compiles down to Prolog
  • Oz/Mozart, a multiparadigm language
  • Visual Prolog, language, a strongly typed object-oriented extension of Prolog, with a new syntax

References

[edit]
  1. ^"Release 22.01.8". 8 September 2023. Retrieved18 September 2023.
  2. ^abcThe Mercury Project - Motivation
  3. ^The Mercury Project - Benchmarks
  4. ^Somogyi, Zoltan; Henderson, Fergus; Conway, Thomas (October–December 1996)."The execution algorithm of Mercury: an efficient purely declarative logic programming language".Journal of Logic Programming.29 (1–3). Mercurylang.org:17–64.CiteSeerX 10.1.1.46.9861.doi:10.1016/S0743-1066(96)00068-4. Retrieved2008-08-30.
  5. ^Mazur, Nancy (May 2004).Compile-time garbage collection for the declarative language Mercury(PDF) (Thesis). Katholieke Universiteit Leuven.
  6. ^ODASE
  7. ^Adapted fromRalph Becket's Mercury tutorial

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Mercury_(programming_language)&oldid=1308250483"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp