[m-dev.] Re: proposal: user-defined equality predicates

Peter Schachte pets at cs.mu.oz.au
Fri Jun 27 14:11:01 AEST 1997

On Fri, 27 Jun 1997, Andrew Bromage wrote:

> >I propose to extend Mercury to support user-defined equality predicates
> >for user-defined types.  The following is a proposed new chapter for the
> >Mercury Language Reference Manual describing this feature.  It is probably
> >a bit short on rationale and examples, but please let me know what you think.
>                 ^^^^^^^^^
> I'd like to see some of this. :-)

My rationale for wanting this is that non-canonical types don't work in
Mercury (or any other logic programming language I know of).  Fergus'
set-as-unordered-list example illustrates it quite well.  If sets are
implemented as unordered lists, *users* of that type have to be very
careful never to unify two such entities, or they may get the wrong
result.  E.g., set([1,2]) = set([2,1]) must succeed, otherwise you
haven't faithfully implemented sets.  Implied modes for predicates
on this type also won't work.

> Unification has the following two properties which IMO are important to
> maintain, but the compiler cannot ensure:
> 	- (X = Y) => (p(X) <=> p(Y))

Aside from the caveat Fergus put in the footnote, and aside from problems 
the compiler will complain about when you have a goal that can fail after 
a deconstruction (which will be cc_multi) I think this property is
maintained.  I'm sure Fergus can argue this more convincingly.

> 	- It always terminates.  If you ignore higher-order values.

and functions.

:- func loop = int.
:- mode loop = out is det.
loop = loop.

... :- loop = 3.

(BTW, I still think it's at best a misfeature that the compiler will let
me get away with calling this det). 

> >   * If the program contains any deconstruction unification or switch
> >     on a variable of type T that could fail, other than unifications
> >     with mode `(in, in)', then it is a compile-time error.
> Including in the ADT implementation?


-Peter Schachte      URL:  http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU     PGP:  finger pets at for key
    [A computer is] like an Old Testament god, with a lot of rules
    and no mercy.  -- Joseph Campbell

More information about the developers mailing list