Mercury belongs to the logic programming paradigm and it combines features of languages such as Prolog and Haskell. The programmer must declare the types of each predicate argument, along with the modes each parameter takes, and as an extra restriction, the determinism of each predicate must be given.
All this information is strictly checked by the compiler, which rejects the program if it cannot prove that every predicate fulfils its declaration. The result of these strict type, mode and determinism proofs is that a compiled Mercury program is guaranteed to avoid certain classes of runtime errors, and the Mercury compiler takes advantage of this fact by optimising the code it generates [25].
The Mercury distribution includes a large number of standard libraries which provide frequently used types, data structures and the common functions and predicates that act on them [26]. The list module, for example, provides the generic list type and functions that act upon lists such as the well known, append, head or tail functions.
There are six possible determinism modes for a predicate, and the one that must be declared depends on the number of solutions that the predicate could return, and whether it may fail before the first solution is found. A summary is given in Table 2.3.
| zero solutions | 1 solution | > 1 solution | |
|---|---|---|---|
| can fail | fail | semidet | nondet |
| cannot fail | erroneous | det | multi |