[mercury-users] Newbie problem. :)
Rob
zharradan at suffering.org
Sat Jun 12 18:38:50 AEST 1999
Hello everybody.
I have a week inbetween exams, so I thought I would take some time off
from studying and work on learning Mercury.
I thought I would try something simple, making an insertion sort for a
list of integers. However, if you think I could create code that
compiles, then you are mistaken. :D
heh. I found a few silly errors that I had made, and worked out the hard
way that "insert" is allready defined somewhere in the standard library.
heh.
The following is my code, and then I'll paste the error I am getting.
--------
% Lets see if I can't do some sorting.
:- module blah.
:- interface.
:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is det.
:- implementation.
:- import_module list, int.
:- pred insertion_sort(list(int), list(int)).
:- mode insertion_sort(in, out) is det.
:- pred my_insert(int, list(int), list(int)).
:- mode my_insert(in, in, out) is det. <-- Line 18
main -->
{ X = [4,2,3,1] },
{ insertion_sort(X, Y) },
io__write(Y),
io__nl.
insertion_sort(X, Y) :-
(
X = [Hd | Tl],
insertion_sort(Tl, Z),
my_insert(Hd, Z, Y)
;
X = [],
Y = []
).
my_insert(X, Y, Z) :-
(
Y = [Hd | Tl],
(
X =< Hd, <-- Line 40
Z = [X | [Hd | Tl]]
;
X > Hd,
my_insert(X, Tl, W),
Z = [Hd | W]
)
;
Y = [],
Z = [X]
).
-------
[zharradan at blacksand tmp]$ m -E blah.m
blah.m:018: In `my_insert(in, in, out)':
blah.m:018: error: determinism declaration not satisfied.
blah.m:018: Declared `det', inferred `nondet'.
blah.m:040: call to `=<(in, in)' can fail.
blah.m:043: call to `>(in, in)' can fail.
blah.m:042: Disjunction has multiple clauses with solutions.
I am obviously missing something here, but I thought this was the way
things were supposed to work - part of the disjunction fails, and it
checks against the rest..
Help. :)
Thanks,
Rob
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list