[mercury-users] determinism not satisfied
Ralph Becket
rbeck at microsoft.com
Wed Jul 11 19:05:26 AEST 2001
> From: Terrence Brannon [mailto:tmbranno at oracle.com]
> Sent: 11 July 2001 09:34
>
> If anyone could help me get this simple program to work, I would
> appreciate it. Program and compilation error messages follow.
>
> % p.14 "Clause and Effect" by William Clocksin
>
> :- module border.
> :- interface.
> :- import_module io.
>
> :- pred main(io__state::di, io__state::uo) is det.
>
> :- implementation.
> :- import_module std_util.
>
> main -->
> { border("sussex",L) }, io__write_string(L).
>
> border("sussex","kent").
> border("sussex","surrey").
>
> adjacent(X,Y) :- border(X,Y).
> adjacent(X,Y) :- border(Y,X).
>
> affordable(X,Y) :- adjacent(X,Z), adjacent(Z,Y).
You haven't supplied type or mode declarations for these predicates.
> [localhost:mercury/lexparse/border] metaperl% mmc --infer-all border.m
> border.m:015: Inferred :- pred border(string, string).
> border.m:018: Inferred :- pred adjacent(string, string).
> border.m:021: Inferred :- pred affordable(string, string).
So the compiler has inferred their types for you.
> border.m:007: In `main(di, uo)':
> border.m:007: error: determinism declaration not satisfied.
> border.m:007: Declared `det', inferred `nondet'.
> border.m:013: call to `border(di, uo)' can fail.
> border.m:013: call to `border(di, uo)' can succeed more than once.
And it looks like it's had a go at inferring modes, too, although
these look a bit strange to me.
> border.m:013: In clause for `main(di, uo)':
> border.m:013: in argument 2 of call to predicate
`io:write_string/3':
> border.m:013: mode error: variable `DCG_0' has instantiatedness
`mostly_unique',
> border.m:013: expected instantiatedness was `unique'.
This is a nondeterministic program, but main/2 must be either det or
cc_nondet or cc_multi.
> border.m:015: Inferred :- mode border(di, uo) is nondet.
Ah yes, here we go.
Here's what you want:
:- module border.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is cc_nondet.
:- implementation.
:- import_module string.
:- pred border(string, string).
:- mode border(in, out) is nondet.
:- mode border(out, in) is nondet.
border("sussex", "kent").
border("sussex", "surrey").
...
:- pred adjacent(string, string).
:- mode adjacent(in, out) is nondet.
adjacent(X, Y) :- border(X, Y).
adjacent(X, Y) :- border(Y, X).
:- pred affordable(string, string).
:- mode affordable(in, out) is nondet.
affordable(X, Y) :- adjacent(X, Z), adjacent(Z, Y).
- Ralph
--------------------------------------------------------------------------
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