[mercury-users] determinism not satisfied

Robert Bossy bossy at ccr.jussieu.fr
Wed Jul 11 22:29:59 AEST 2001


[ 11 Jul 2001 01:34:18 -0700 ] Terrence Brannon <tmbranno at oracle.com> -> mercury-users at cs.mu.OZ.AU

> 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).
> 
> 
> [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).
> 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.
> 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'.
> border.m:015: Inferred :- mode border(di, uo) is nondet.
> For more information, try recompiling with `-E'.

I would not advise the --infer-all option until you become very familiar with mercury.

The compiler inferred:
:- mode border(di, uo) is nondet.

Why?

1) There is a possibility where the call to border(di,uo) fails, eg:
	border("champagne",_)
	border("provence",_)

2) There is a possibility where the call to border(in,out) succeeds several times, eg:
	border("sussex",_)

I attached an exercice code I wrote to teach determinism.

RB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: choose_det.m
Type: application/octet-stream
Size: 1296 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/users/attachments/20010711/80cf6b7c/attachment.obj>


More information about the users mailing list