[mercury-users] uniqueness

valery at freesurf.fr valery at freesurf.fr
Mon Jun 12 22:27:37 AEST 2006


Hello,

In my first attemps to use Mercury, I run into some problems related to
uniqueness. It's no surprise, it was the same with Clean !

:- pragma promise_pure(main/2).
main(!IO) :-
  N = 3,
  B = new(N, N, 0),
  mark((1, 2), 1, B, B1), % problem 1
%  (
%    in_bounds(B1, X, Y),
%    format("(%d, %d) -> %d\n", [i(X), i(Y), i(B1 ^ elem(X, Y))], !IO) %
problem 2
%  ),
  format("%d\n", [i(B1 ^ elem(1, 2))], !IO),
  impure report_stats.

:- type board == array2d(int).
:- type point ---> (int, int).

:- pred mark(point::in, int::in, board::array2d_di, board::array2d_uo) is
det.
mark((X, Y), V, B0, B) :- B = B0 ^ elem(X, Y) := V.

:- pred is_free(point::in, board::in) is semidet.
is_free((X, Y), B) :- B ^ elem(X, Y) = 0.

1/ When I try to use the state variable syntax, that is, I replace "B, B1"
with "!B", the compiler chokes.

2/ The commented out portion is rejected as well. I suspect this is
because nondeterministic predicates are not allowed to perform IO, but the
error message doesn't state it clearly. What is the common idiom to output
the contents of a collection ?

3/ More generally, I need to model states more complex than a single
array, like several arrays plus a couple of integers. As I understand the
documentation, this is not yet possible, because uniqueness is limited to
IO and the array hacks. Is uniqueness for user defined types planned for
near future ?

-- Valery



--------------------------------------------------------------------------
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