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

Fergus Henderson fjh at cs.mu.oz.au
Tue Jul 8 22:52:55 AEST 1997


Andrew Bromage, you wrote:
> G'day all.
> 
> Something else that's occurred to me with the user-defined equality
> predicates.  How do they interact with compare/3? 

Yes, this is an important issue. 
Another issue is how do they interact with arg/3, functor/3, etc.?
I discovered these issues when I started implementing them.

> Would it still be
> true that compare((=), X, Y) <=> X = Y?  Is this even an important
> property to maintain?

In my current implementation, compare/3 calls error/1 if you call it
for a type with a user-defined equality pred.  This preserves the
above property, albeit in a rather unfriendly way.  However, I don't
have a solution for get_functor/3, argument/3, and deconstruct/4.

Here's part of my draft log message:

 | compiler/unify_proc.m:
 | 	For types with user-defined equality predicates, make the
 | 	unification predicate for that type just forward to the
 | 	equality predicate that the user specified.
 | 	For compare/3, we currently just call error/1
 | 	(indirectly, via builtin_compare_non_canonical_type/3).
 | 	For index/2, we just always return -1 (meaning index unavailable).
 | 	XXX what should we do for arg and functor, io__read and io__write?
 | 	Currently they break referential transparency,
 | 	if used on non-canonical types.
 | 	We really need type classes for arg, functor, etc.,
 | 	and we need a way for the user to override the default
 | 	instance definitions for these type classes for non-canonical types.
 | 
 | 	For the moment, I suppose we just have to leave it broken:
 | 	arg, functor, io__read, io__write, etc. are just not referentially
 | 	transparent, if used on non-canonical types.
 | 	We can fix this when we have type classes.

Because of these problems, user-defined equality predicates should not
become part of the language until after type classes.  I'll probably
commit the changes, but leave the documentation commented out.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list