[m-dev.] Types with user defined equality.

Fergus Henderson fjh at cs.mu.OZ.AU
Tue May 15 14:37:34 AEST 2001


On 14-May-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> In the fast string module I just posted, it would have been nice
> to be able to declare the (structured) str type as having an
> equality pred, but have this notion of equality visible only
> *outside* the defining module.

Having context-dependent semantics like this would make it harder
to reason about programs.

It would also make it much more difficult for the compiler to
perform optimizations such as intermodule inlining.

Which notion of equality would apply for procedures
called from the defining module?  Suppose I see a recursive
procedure that deconstructs a list, and replace it with
a call to list__foldl.  If list__foldl is being used in the
`mode foldl(pred(in, in, out) is semidet, in, in, out) is semidet'
mode, then this might change the semantics, since the equality
is now being done in the list module rather than in the module
that calls list__foldl.

> As it stands, you have to torture your code (or make everything
> cc_multi) if you pattern match against a d.u. type with user-defined
> equality, making it far less attractive.

How about replacing the `promise_only_solution' higher-order predicate with
a `promise_only_solution' pragma, or a new builtin goal type.
Would that solve the problem?

> Indeed, searching on the
> string "where equality" fails to come up with any instances of its
> use in extras or the library (even set.m doesn't use it).

For `set', there's no need to use it; the standard equality is the right one.
`set_unordlist' ought to use it, though.  The reason that it doesn't is
because of the lack of any way to have user-defined comparison.

There are several modules in the extras distribution that use it,
in particular trailed_update/var.m, lazy_evaluation/lazy.m, and
clpr/cfloat.m.

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