[mercury-users] Modes for partly uninstantiated list

C. Heppner ethrandil at gmx.net
Sun Feb 4 03:13:26 AEDT 2007


Hi,

I've been doing a little thing about a game called tick-tack-toe in
prolog. Now I'd like to try the same in mercury.

The predicate I am having trouble with is:

win([A,B,C,_,_,_,_,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
win([_,_,_,A,B,C,_,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
win([_,_,_,_,_,_,A,B,C]) :- atom(A), atom(B), atom(C), A=B, B=C.

win([A,_,_,B,_,_,C,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
win([_,A,_,_,B,_,_,C,_]) :- atom(A), atom(B), atom(C), A=B, B=C.
win([_,_,A,_,_,B,_,_,C]) :- atom(A), atom(B), atom(C), A=B, B=C.

win([A,_,_,_,B,_,_,_,C]) :- atom(A), atom(B), atom(C), A=B, B=C.
win([_,_,A,_,B,_,C,_,_]) :- atom(A), atom(B), atom(C), A=B, B=C.

I've tried different things in mercury but didn't succeed. My
test-code looks like the following:


:- pred win(list(character)).
:- mode win(list_skel >> list_skel) is semidet.

win([A,B,C,_,_,_,_,_,_]) :- A=B, B=C.

main(!IO) :-
	L = [x,x,x,_,_,_,_,_,_],
	(if win(L)
		then write_string("win", !IO)
		else write_string("not(win)", !IO)),
	nl(!IO).

The errors I get:

ticktack.m:043: In clause for `main(di, uo)':
ticktack.m:043:   in argument 1 of call to predicate `ticktack.win/1':
ticktack.m:043:   sorry, implied modes not implemented.
ticktack.m:043:   Variable `L' has instantiatedness
ticktack.m:043:   `unique(list.'[|]'(unique(x),
unique(list.'[|]'(unique(x),
ticktack.m:043:   unique(list.'[|]'(unique(x), unique(list.'[|]'(free,
ticktack.m:043:   unique(list.'[|]'(free, unique(list.'[|]'(free,
ticktack.m:043:   unique(list.'[|]'(free, unique(list.'[|]'(free,
ticktack.m:043:   unique(list.'[|]'(free,
unique((list.[]))))))))))))))))))))',
ticktack.m:043:   expected instantiatedness was `bound((list.[]) ;
ticktack.m:043:   list.'[|]'(free, bound((list.[]) ;
list.'[|]'(free, ...))))'.
ticktack.m:018: In clause for `win(((list.list_skel) >>
(list.list_skel)))':
ticktack.m:018:   mode error in unification of `A' and `B'.
ticktack.m:018:   Variable `A' has instantiatedness `free',
ticktack.m:018:   variable `B' has instantiatedness `free'.


I would intuitively try it with something like that (which doesn't
work, too):

win([A::in,A::in,A::in,_,_,_,_,_,_]).


Do you guys have an idea of how I could do that or what I should
read about modes (I've read something, p.e.
http://www.cs.mu.oz.au/research/mercury/information/doc-release/mercury_ref/Predicate-and-function-mode-declarations.html#Predicate-and-function-mode-declarations).

mfg
- c. heppner

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20070203/0ba0d110/attachment.sig>


More information about the users mailing list