Tuesday, October 9, 2012

Mercury Programming Language

As part of graduate school requirement, we were asked to report on a new programming language and was tasked to report on Mercury.

Wikipedia defines Mercury as, "a functional logic programming language geared towards real-world applications. It is developed at the University Of Melbourne Computer Science department under the supervision of Zoltan Somogyi. The first version was developed by Fergus Henderson, Thomas Conway and Zoltan Somogyi and was released on April 8, 1995. "

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.

It is related to Prolog but it has the following unique features:
  • It combines the strengths of declarative programming with advanced static analysis and error detection features;
  • It’s compiled  rather than interpreted.
  • It has a sophisticated, strict type and mode system making it the  fastest logic  language in the world by wide margin.
  • It allows modularity, separate compilation, and numerous optimization/time trade-offs. 
Mercury is a free software and may run in Unix, Linux or Windows but with the appropriate installation package.  I personally used Mercury 11.07.1 that is bundled up already for Windows and does not require Cygwin anymore.
 To display a sample code, click the link below.

% displaying ‘Hello World’ -- this is a comment
 :− module hello.
:− interface.
:− import module io.
:− pred main(io::di, io::uo) is det.
:− implementation. main(IOState in, IOState out)
:− io.write string(“Hello, World!\n”, IOState in, IOState out).