Content deleted Content added
No edit summary |
|||
Line 64:
== Examples ==
[[Hello world program|Hello World]]
<pre>
:- module hello.
Line 74:
main(!IO) :-
io.write_string("Hello, World!\n", !IO).
</pre>
Calculating the 10th [[Fibonacci number|Fibonacci number]]:
<pre>
:- module fib.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
:-func fib(int) = int.
fib(N) = (if N =< 2 then 1 else fib(N - 1) + fib(N -2)).
main(!IO) :-
io.write_string("fib(10) = ", !IO),
io.write_int(fib(10), !IO),
io.nl(!IO).
</pre>
|