Welcome to the Dictionary of Programming Languages, a compendium
of computer coding methods assembled to provide information and
aid your appreciation for computer science history.
Browse the dictionary by clicking on a section:
Get a full dump of the dictionary:
List of Names
- Language type:
L - Rule-based or logical
Mercury is a logic programming language
with some functional language features.
It was designed to give the
semantic benefits of declarative
programming and the speed and error-checking
of procedural programming.
The syntax of Mercury is similar to that
of Prolog, but supports additional
constructs that declare type, mode,
and other constraints.
Data types supported by the language
include: integers, reals, strings, and
a very flexible record/union type;
the standard library supports a wide
variety of collection types including
arrays, lists, trees, maps, etc.
As a hybrid
programming language, Mercury does
not support conventional procedural
control flow constructs. It does
support higher-order function
operators like curried functions, filters,
Unlike most logic programming languages,
Mercury is not interpreted. Instead,
the compiler translates Mercury code
modules into portable C. This gives
Mercury additional portability and speed,
but prevents it from creating and
evaluating new code on the fly.
Since Mercury is purely functional
(side-effect-free) the I/O model
depends on the notion of an "io_state"
value. This makes output a little
tricky, but doesn't break the semantics.
A free implementation of Mercury for
Unix and Windows platforms is available
free. Mercury is distributed with some
Linux systems. In order to take advantage
of Mercury, however, the target system must
have a good C compiler.
Mercury Project, University of Melbourne, 1993.
- See Also:
Mercury is designed to fold some of the
attractive features of mainstream
'imperative' languages into a logic
programming system, advantages like
speed, scalability, strong type
checking, and early error detection.
Their approach is basically allow
the programmer to convey to
the language system with a good deal of
additional information about types, modes,
determinism, purity, and other aspects
of the code. Using this information, the
Mercury compiler can perform many
optimizations not possible in looser
languages. Also, of course, Mercury
is compiled while most other logic
languages are interpreted: the
compiler generates C code from which
a native C compiler can generate a
The C code generated by the Mercury
compiler can employ various non-standard
C features, such as in-line assembly
and register globals,
if the C compiler supports them. With all
of these optimizations turned on, Mercury
is roughly an order of magnitude faster
than normal Prolog,
and twice as fast as the fastest
commercial Prolog systems.
Interestingly, the current free Mercury
compiler is written in itself, having
been bootstrapped from Prolog.
- Sample code:
% An example of finding primes using a sieve
% (adapted from a logic programming benchmark in mercury)
:- import_module list, int.
:- pred primes(int, list(int)).
:- mode primes(in, out) is det.
:- pred integers(int, int, list(int)).
:- mode integers(in, in, out) is det.
:- pred sift(list(int), list(int)).
:- mode sift(in, out) is det.
:- pred remove(int, list(int), list(int)).
:- mode remove(in, in, out) is det.
primes(Limit, Ps) :- integers(2, Limit, Is), sift(Is, Ps).
integers(Low, High, Result) :-
( Low =< High ->
M is Low + 1,
Result = [Low | Rest], integers(M, High, Rest)
Result = 
sift([I | Is], [I | Ps]) :- remove(I, Is, New), sift(New, Ps).
remove(_P, , ).
remove(P, [I | Is], Result) :-
M is I mod P,
( M = 0 ->
Result = Nis, remove(P, Is, Nis)
Result = [I | Nis], remove(P, Is, Nis)
Descriptions in this dictionary are ©1997-99 Neal Ziring. Some
examples copyright of their respective authors. Some
technologies and languages are trademarked. Permission to
copy descriptions is granted as long as authorship credit is preserved.
Comments on this dictionary, corrections and suggestions, are all welcome.
Please use email, the address is email@example.com
[Ziring MicroWeb Home]
Dictionary and script maintained by Neal Ziring, last major modifications 3/18/98. Most recent
additions to dictionary and master list, 1/00.