[m-dev.] User defined comparison and equality
Simon Taylor
stayl at cs.mu.OZ.AU
Fri Apr 11 01:22:33 AEST 2003
On 10-Apr-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 10-Apr-2003, Fergus Henderson <fjh at cs.mu.oz.au> wrote:
> > On 10-Apr-2003, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > > If a type has user-defined comparison, are unifications in the
> > > in = in is semidet mode implemented as calls to compare((=))?
> >
> > Only if the type does not have a user-defined equality.
> >
> > > Otherwise it seems to me that we can have A \= B but
> > > compare((=), A, B).
> >
> > Yes, that is a correct interpretation of the current language reference
> > manual.
> >
> > > The requirement that this not be the case is not listed as a
> > > programmer obligation in the reference manual,
> >
> > Right -- currently there is no such obligation.
> >
> > Should there be?
>
> After thinking about it a bit more, I think there should.
That was always my intention. The only difference between
the equality and comparison predicates should be efficiency.
Simon.
Estimated hours taken: 0.25
Branches: main
doc/reference_manual.texi:
Document the requirement that if the user supplies
both unification and comparison predicates for a type,
all [X, Y] (unifypred(X, Y) <=> comparepred((=), X, Y)).
Index: reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.273
diff -u -u -r1.273 reference_manual.texi
--- reference_manual.texi 21 Feb 2003 01:57:23 -0000 1.273
+++ reference_manual.texi 10 Apr 2003 15:18:16 -0000
@@ -3560,6 +3560,12 @@
with arguments of that type are evaluated as if they were calls
to @var{comparepred}.
+A type declaration may contain a
+ at samp{where equality is @var{equalitypred}, comparison is @var{comparepred}}
+specification only if in addition to the conditions above,
+ at samp{all [X, Y] (@var{comparepred}((=), X, Y) <=> @var{equalitypred}(X, Y))}.
+The compiler is not required to check this.
+
@node Higher-order
@chapter Higher-order programming
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list