Files
mercury/benchmarks/progs/fibonacci/fib.m
Paul Bone ea06fd8cde Add the benchmarks directory into the main Mercury repository.
This was a seperate repository in CVS and so it missed the conversion.

benchmarks/
    As above.
2013-01-04 12:13:53 +11:00

32 lines
491 B
Mathematica

:- module fib.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, list, string, require.
main(!IO) :-
N = 46,
fib(N, F),
io.format("fib(%d) = %d\n", [i(N), i(F)], !IO).
:- pred fib(int::in, int::out) is det.
fib(N, F) :-
( N < 0 ->
error("fib(N, _): N must be greater than 0")
; ( N = 0 ; N = 1 ) ->
F = 1
;
fib(N-1, FA),
fib(N-2, FB),
F = FA + FB
).