[m-dev.] Foreign type compare and unification

Zoltan Somogyi zs at cs.mu.OZ.AU
Sun May 12 03:26:57 AEST 2002


On 12-May-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> Is there any reason why we have user-defined equality but not
> user-defined comparison? Not having user-defined comparison
> makes it difficult to use data types such as cords (strings
> represented as trees for constant-time append).

Yes. In many cases, the user-defined comparison routine would work with
a partial order, not a total order, and this is incompatible with the
determinism of compare/3.

Ideally, we should let users whose define types with non-standard equality
choose between three options:

- no comparison defined on the type;
- comparison defined on the type as a total order;
- comparison defined on the type as a partial order.

Implementing this three-way would be quite difficult, since we would need
to modify the builtin assumption that the types bound to universally
quantified type variables have a total order comparison. (At the moment,
we make this assumption come true for user defined types by automatically
aborting on attempts to compare them.)

Implementing a choice between the first two alternatives should not be too
difficult, and as you say, may be useful enough to justify the effort.

Zoltan.
--------------------------------------------------------------------------
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