Description #
Mercury is a logic-functional programming language designed for declarative programming with strong typing and determinism, combining features of Prolog and functional programming.
History #
Developed in the 1990s by Zoltan Somogyi and others at the University of Melbourne, Mercury emphasizes pure logic programming with strong type and mode systems to improve program reliability and efficiency.
Hello World Code #
:- module hello.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.write_string("Hello, World!\n", !IO).
How to Run #
Option 1: Online
Try Mercury Online
Option 2: Local
- Install Mercury:
sudo apt-get install mercury
Compile and run:
mmc hello.m
./hello
Key Concepts #
- Pure logic-functional paradigm
- Strong static typing and mode systems
- Deterministic and nondeterministic predicates
- Module system and separate compilation
- Tail call optimization
- Declarative debugging
- Garbage collection
- Integration with C libraries
- Compilation to efficient native code
- Used in AI and constraint solving
Try It Online #
Fun Facts #
- Mercury programs have no side effects unless explicitly stated.
- The mode system helps the compiler optimize and verify code correctness.
- Mercury has been used to build commercial-grade compilers and AI tools.