Prolog is probably one of the smartest language I ever studied in my life. To be honest, I discovered Prolog after Erlang, and, because Erlang is a language for the real world, I wanted to understand and know more about the origin of this one. Well, Erlang was designed in the 80's, by Joe Armstrong. The first implementation of Erlang was a kind of derivative of Prolog wrote in Smalltalk. After a talk with one of his colleague, he decided to reimplement all the concent in Prolog...

Well, Prolog is a dynamically typed language, a bit like LISP and other high level languages. Mercury, in other hand, is another implementation of Prolog, but, with a bit of Haskell. To make thing clear, Mercury is a statically typed Prolog language. It seems that only a few people around the world know it, and, because I also love Haskell, I decided to try use it.

# Features

# Syntax

A mercury source code is a simple text file containing different parts.

touch my_module.m

The header of the file will contain the name of the module followed by the difference interface (or exported functions), the one you will have access from the other part of the code. Mercury is a kind of pure functional language and will force the developer to separate the function with side-effects and the pure function (without side effects). If you need to print something on the screen, or create a remote connection, those functions will make side effects, and you will need to import the io module.

:- module my_module.
:- interface.
:- import_module io.

Each function need also to be specified. That means that you need to create a definition of the function by defining what kind of variables this last one will require to work. Here we define the function called main, both arguments are defined by io types. The difference here is that the first argument is an input and the last is an output. Mercury needs to know if the function is determinist or not.

:- pred main(io:di, io:uo) is det.

Now, the implementation can be made, the compiler need to know where it starts by explicitely adding the implementation preprocessor term.

:- implementation.

main/2 function uses here a syntactic sugar with !IO. This macro create 2 variables to match the io state. Every function with side effects must have these variables defined. main/2 uses io.write_string/3 to print a message (test) to the user screen.

main(!IO) :-
    io.write_string("test\n", !IO).

It's the time to compile my_module module by using the mercury compiler or mmc. By default, with the --make flag, the compiler will look in the current directory and build all files ended with .m. This command will generate an executable program called my_module.

mmc --make my_module
./my_module
# return:
# test

# Understanding Types

# Library

# Hello World (exercice)

# Caesar Cipher (exercice)

# Cross Compilation

# Conclusion

# Resources

# Annexes

Because when I like

# Porting mercury on OpenBSD

# Porting mercury on VoidLinux

# Porting mercury on AlpineLinux