[mercury-users] equality functions

David Overton dmo at ender.cs.mu.oz.au
Mon Mar 20 17:20:49 AEDT 2000


On Mon, Mar 20, 2000 at 11:27:34AM +1100, Michael Day wrote:
> 
> Is it useful (or possible) to define functions such as:
> 
> :- func '<'(T, T) = bool.
> :- func '='(T, T) = bool.
> ...
> 
> and so forth?

Not sure if it's useful.  What sort of use did you have in mind?

> Would this cause awful conflicts with their current use as predicates, or
> would their use be unambiguous?

Their use should be unambiguous in most cases, although using '='/2 as
a function could get confusing for human readers.

> I tried to construct a more general "succeeded" function that takes a
> predicate and returns bool, but was unable to get the modes correct. Is
> such a predicate even possible?

:- func succeeded(pred) = bool.
:- mode succeeded((pred) is semidet) = out is det.

succeeded(P) = ( P -> yes ; no ).

You can use this for any predicate without output arguments by
currying the inputs, including '<', '>', etc.
Note that you need parenthesis around `pred' in the mode declaration
because `pred' is an operator.


David
-- 
David Overton       Department of Computer Science & Software Engineering
PhD Student         The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159     http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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