[mercury-users] equality functions

Ralph Becket rbeck at microsoft.com
Mon Mar 20 22:13:21 AEDT 2000


> Is it useful (or possible) to define functions such as:
> 
> :- func '<'(T, T) = bool.
> :- func '='(T, T) = bool.
> ...
> 
> and so forth?
> 
> Would this cause awful conflicts with their current use as 
> predicates, or would their use be unambiguous?

This should just be a normal case of overloading operators, so
ambiguity will only arise if (a) your definitions do not have
a disjoint type signature with other functions of the same
name and arity in the same scope and (b) you don't module-
qualify the names.

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

std_util.m defines maybe_pred/2:

:- pred maybe_pred(pred(T1, T2), T1, maybe(T2)).
:- mode maybe_pred(pred(in, out) is semidet, in, out) is det.

If you want a simpler version you could write

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

succeeded(P) :-
	( if call(P) then yes else no ).

and generalise if you want to add arguments.

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 

> -----Original Message-----
> From: Michael Day [mailto:mcda at students.cs.mu.oz.au]
> Sent: 20 March 2000 00:28
> To: mercury-users at cs.mu.OZ.AU
> Subject: [mercury-users] equality functions
> 
> 
> 
> 
> 
> Michael
> 	
> 
> --------------------------------------------------------------
> ------------
> 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
> --------------------------------------------------------------
> ------------
> 
--------------------------------------------------------------------------
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