Determinism case

Gustavo A. Ospina gos at info.fundp.ac.be
Fri Feb 26 22:36:51 AEDT 1999


Hi all.

I'm trying to test the behaviour of Mercury translating specifications with
universal quantifiers. One of these tests is this procedure who computes
the minimum element of an integer list:

minlist(L,M) :-
	list__member(M,L),
	all [X] (list__member(X,L) => M =< X).

The mode declaration is :- mode minlist(in,out) is nondet. I can't declare
it 'det' because the compiler rejects this with a mode error (infers
'nondet').

Anyway, I checked that this procedure has only one solution using
'solutions', and can be used in procedures (like 'main', being declared as
cc_multi)  with an if-then-else.

This is not a criticism to the Mercury determinism analyzer, I want just to
show a case (rare) in that fails this analysis. In fact, the compiler help
me to make work well this example with their error messages.

In general, use of universal quantifier is rare and in most cases leads to
mode errors in the code (as I had see in another tests), but the idea is to
find mechanisms to translate such quantifiers in correct mercury code (for
example, when the universal quantifier seems to be a loop over one
collection structure).

Best Regards.

+ Gustavo.

Attach my code test.
-------------- next part --------------
:- module minlist.

:- interface.

:- import_module io, list, int.

:- pred main(io__state,io__state).
:- mode main(di,uo) is det.

:- pred minlist(list(int),int).
:- mode minlist(in,in) is semidet.
:- mode minlist(in,out) is nondet.

:- implementation.

:- import_module std_util.

main -->
	% 10 occurs twice in this lists, so, there are two minimum elements
	{solutions(pred(M::out) is nondet :- minlist([67,93,35,10,11,23,45,10,58,43,88],M),LS)},
	% Just prints "[10]"
	io__write(LS),
	io__nl.

%---Definition of minlist---%

minlist(L,M) :-
	list__member(M,L),
	all [X] (list__member(X,L) => M =< X).
-------------- next part --------------


+----------------------------+----------------------------------+
| Gustavo A. Ospina          | Phone    : +32 (81) 72 49 71     |
| Institut d'Informatique    | Fax      : +32 (81) 72 49 67     |
| F.U.N.D.P.  Namur          |                                  |
| Rue Grandgagnage 21        | email    : gos at info.fundp.ac.be  |
| 5000 - Namur (Belgium)     |                                  |
+----------------------------+----------------------------------+


More information about the users mailing list