Mercury
- Appeared in:
- 8 Apr 1995
- Influenced by:
- Paradigm:
- Typing discipline:
- Versions and implementations (Collapse all | Expand all):
Mercury is a logic/functional programming language meant to be used for large-scale program development. It combines the expressive means of declarative programming with static analysis and error detection features.
Mercury is developed at the University Of Melbourne Computer Science department. The first version was developed by Fergus Henderson, Thomas Conway and Zoltan Somogyi and released on April 8, 1995. The official implementation of the language, Melbourne Mercury Compiler, is the only one so far.
Language features:
- Mercury is a purely declarative language; predicates and functions have no non-logical side effects. Operations which would normally have certain side effects, like I/O, avoid this by taking a dummy value “state of the world” as one of the parameters, destroying it and returning the new one (possibly with other results). I/O can be done only in parts of the program which won’t be backtracked.
- The standard library provides several abstract data types which represent collections of items with various operations.
- Mercury’s type system is based on many-sorted logic with parametric polymorphism, similar to that of Haskell. New predicates need an explicit declaration of their signatures; other than that, types of all variables in the program are deduced by the compiler.
- Mercury implements a moded system which requires a declaration of instantiation state of all predicate arguments. So far there are only two states — “fully input” and “fully output”. This allows to detect a large class of errors at compile time.
- The determinism system of the language requires that each mode of each predicate has a declaration of how many times will this predicate succeed: exactly once (det), at most once (semidet), at least once (multy) or an arbitrary number of times (nondet). This allows the compiler to try to prove the determinism of the program based on a simple set of rules.
- a module system which allows separate compilation.
- higher-order programming support with closures, currying and lambda expressions.
Mercury logo
Links:
Examples:
Hello, World!:
Example for versions Mercury 10.04 :- module hello.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.write_string("Hello, World!\n", !IO).
Comments
]]>blog comments powered by Disqus
]]>