[mercury-users] Unique mode questions

Terrence Brannon princepawn at earthlink.net
Fri Apr 20 12:56:20 AEST 2001


In looking at this section of the manual I developed the following
questions:

1- The manual states:

 Mercury also provides "unique" insts `unique' and `unique(...)' which
 are like `ground' and `bound(...)' respectively, except that they
 carry the additional constraint that there can only be one reference
 to the corresponding value.

So my question is, what is meant by one reference to a value? Does
that mean I cannot access the memory contents more than once? For
example, here is a predicate with a unique-out variable:

:- pred string__length(string, int).
:- mode string__length(in, uo) is det.

it is wrong for me to do the following:

string__length(S,L), use_it_once(L), use_it_again(L).

2- Continuing, the manual states:

 There is also an inst `dead' which means that there are no references
 to the corresponding value, so the compiler is free to generate code
 that reuses that value. 

Now the obvious question is: why would a dead value exist in the first
place?! And the neophyte's intuitive explanation would be:

:- pred list__length_2(list(T), int, int).
:- mode list__length_2(in, in, out) is det.

list__length_2([], N, N).
list__length_2([_ | L1], N0, N) :-
	N1 is N0 + 1,
	list__length_2(L1, N1, N).


... the _ above is a case where the mode could have been dead but
unfortunately the tail of the list was needed. So then the question
remains, why pass something that isn't going to be used? It doesn't
make much sense to have a mode like this in my eyes.

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