Mercury    hoch http://www.cs.mu.oz.au/research/mercury/
 
  Beschreibung: From Mercurys homepage: "Mercury is a new logic/functional programming language, which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features. Its highly optimized execution algorithm delivers efficiency far in excess of existing logic programming systems, and close to conventional programming systems. Mercury addresses the problems of large-scale program development, allowing modularity, separate compilation, and numerous optimization/time trade-offs."


  Fakultät   Michael Neumann
:- module factorial.

:- interface.

:- pred factorial(int::in, int::out) is det.

:- implementation.

:- import_module int.

factorial(N, R) :-
        ( if N =< 1 then
                        R = 1
        else
                        factorial(N - 1, R0),
                        R = N * R0
         ).



 Hello World   Michael Neumann
% Hello World in Mercury
%
% compile with:
%   mmake hello.depend
%   mmake hello

:- module hello.
:- interface.
:- import_module io.

% di=desctructive input, uo=unique output
:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

% "-->" tells that we are using DCG (definite clause grammar), which frees us
% from threading some extra arguments through the code.
main --> io__write_string("Hello World\n").
Gibt "Hello World" auf dem Bildschirm aus.


  Länge einer Liste   Michael Neumann
%
% Calculates the length of a list
%

:- import_module list, int.

:- pred length(list(T)::in, int::out) is det.

length(L, N) :-
        (
                % if L is empty
                L = [],
                N = 0
        ;
                % else 
                L = [_Hd | Tl],
                length(Tl, N0),
                N = N0 + 1
        ).
Bestimmt die Länge einer Liste.