[m-dev.] proposal: user-defined equality predicates
Peter Schachte
pets at cs.mu.oz.au
Fri Jun 27 13:24:10 AEST 1997
This proposal looks good. Just a few nits to pick:
On Thu, 26 Jun 1997, Fergus Henderson wrote:
> For types such as this, which do not have a canonical representation,
> the standard definition of equality is the desired one; we want
... is *not* the desired one...
> To support such types, Mercury allows
> programmers to specify a user-defined equality predicate for
> user-defined types:
>
> :- type set(T) ---> set(list(T))
> where equality is set_equals.
I have one reservation about this syntax: it doesn't allow easy later
extension to support unification of values of different types (but, I
would hope, of the same type class). This seems to me to be a good way to
handle, e.g., unifying an integer and a constrained integer. It could
also be a good way to do some kinds of object-oriented programming (I can
show you an old paper that discusses this, if you like). It's not without
problems, but it seems worthwhile to leave the door open to this.
> * EQUALITYPRED must be the name of a predicate with type `pred(T,
> T)' and mode `(in, in) is semidet'.
What if there are other declared modes? Are they currently ignored for
unification, or are they used where appropriate?
> * 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.
I guess this answers my last question. Is this a limitation that can
later be lifted (to say something like "other than unifications of a mode
which is a declared mode for the EQUALITYPRED.")?
> * If the program contains any deconstruction unification or switch
> on a variable of type T that cannot fail, then that operation has
> determinism `cc_multi'.
Is there some way to turn this back to det? I'd like to be able to
promise that the code I'm writing will compute the same solutions for any
concrete representation of the abstract type.
-Peter Schachte URL: http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU PGP: finger pets at 128.250.37.150 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