# Install on OpenBSD

mkdir src
cd src

# require more packages
pkg_add bison egcc

# get version
ftp http://dl.mercurylang.org/release/mercury-srcdist-20.01.1.tar.gz
tar zxvf mercury-srcdist-20.01.1.tar.gz
cd mercury-srcdist

# you should probably change the prefix if you want to use it
# only with your current user --prefix=${HOME}/local
CC=egcc ./configure 
make PARALLEL=-j2

# only if you want to install it on your system
doas make install

# First code

We will create a file called main.m. This one will contain our first empty code.

touch main.m
emacs main.m

And the content

:- module main.

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

:- implementation.
:- import_module list.

main(!IO) :-
    io.format("", [], !IO).

A mercury program can be cut in many part. The first one is a requirement, and set the name of the module. In our case, the file containing our code is called main.m so, the module will be called main.

:- module main.

The second part defines the interface, the exported predicates by this module and available to others modules. These predicates can be seen by other part of the code. In this part, modules can also be imported, like io module. Exported predicates need to be defined there.

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

The third part defines the implementation. This part is visible from other module during execution. It consists mainly to create the main code with all the algorithms and the complexity.

:- implementation.
:- import_module list.

main(!IO) :-
    io.format("", [], !IO).

!IO is a syntactic sugar created to make the code more readable when using IO, this syntactic sugar replace !IO by 2 variables defined as IO input and IO output. Every time an action is made, IO context changes.

To build our software, mmc mercury compiler can be used.

mmc --make main.m
./main

# Annexes

# Packaging Mercury for OpenBSD

  • https://github.com/niamtokik/openbsd-wip/tree/mercury

# Resources

  • https://mercurylang.org/
  • http://dl.mercurylang.org/index.html