[mercury-users] Confused about "undefined behaviour" of promise_only_solution

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Nov 26 14:29:02 AEDT 2004


On 26-Nov-2004, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > 2) In my app the predicate of interest has many syntactically 
> >    different, but semantically equivalent solutions.
> >    Is is okay to use promise_only_solution within this case?
> 
> Ahh, it sounds as though what you want is user-defined equality.
> User-defined equality is useful where, say, you want to represent sets
> using unordered lists.  In this case you would like Mercury to recognise
> the following identities: [1, 2, 3] = [1, 3, 2] = [1, 1, 3, 1, 2] = ...
> You can do this by supplying your own equality predicate for your set
> type.

Ralph's answer is correct, but he didn't connect the two parts of his answer.
If your predicate has several solutions, but all the solutions are guaranteed
to be semantically equal with respect to the equality theory you have in mind
(just as [1, 2] = [2, 1] when representing sets with unordered lists),
then you can use promise_only_solution on the predicate and everything
will be fine, precisely because the solutions *are* all equal according
to your semantic notion of equality. This is true even if you don't declare
the type involved to have user-defined equality.

Zoltan Somogyi <zs at cs.mu.OZ.AU> http://www.cs.mu.oz.au/~zs/
Department of Computer Science and Software Engineering, Univ. of Melbourne
--------------------------------------------------------------------------
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