user-defined equality predicates (again)

Fergus Henderson fjh at hydra.cs.mu.oz.au
Wed Aug 20 19:36:47 AEST 1997


Hi,

Here's my diff for user-defined equality predicates again.
The only change from last time is that the documentation of
functor/2, argument/2, and deconstruct/4 now mentions that
those predicates abort for non-canonical types.

I plan to commit this RSN.

----------------------------------------------------------------------

Implement support for types with user-defined equality predicates.

Types with user-defined equality predicates are called "non-canonical types";
they may have more than one representation for the same abstract value.
That means that any attempt to deconstruct a value of a non-canonical
type, i.e. any attempt to peek at the representation, must be cc_multi.

This also implies that conceptually speaking, non-canonical types are not
members of the type classes `comparable' (compare/3) or `deconstructible'
(index/2, argument/3, functor/3, deconstruct/5).  Since we don't support
type classes yet, that just means that the type-class checking is done
at runtime, i.e. any call to one of those functions for a non-canonical
type will call error/1 or fatal_error().

To make non-canonical types useful, we really need type classes,
so that the user can provide instance definitions for `comparable'
and `deconstructible' for such types.  It might also be a good idea
to have a type-class `canonicalizable' which provides a function
to convert its argument to some canonical type (that would
require existential types to do nicely, but alternatively we could
just use `univ').

Note that currently the only mechanism for promising that things are
unique is via the C interface.

compiler/det_analysis.m:
	Add code to check unifications that examine the
	representation of a type with a user-defined equality predicate.
	Any such unification must occur in a single-solution context and
	must not be able to fail.  Such unifications determinism have
	determinism cc_multi.

compiler/det_report.m:
	Add code to report errors for misuse of types with user-defined
	equality predicates.  (Also some other stylistic improvements:
	split up a complicated predicate into subroutines, and
	avoid some unnecessary code duplication.)

compiler/prog_data.m:
compiler/hlds_data.m:
	Add a new `maybe(sym_name)' field to the du_type/3 constructor
	to hold the name of the user-defined equality pred for the
	type, if any.

compiler/prog_io.m:
	Add code to parse the new `... where equality is <name>.' syntax.
	Delete the old support for `... where <condition>'.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/mercury_to_goedel.m:
	Print out the new field.

compiler/base_type_layout.m:
compiler/code_util.m:
compiler/dense_switch.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/make_hlds.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/switch_detection.m:
compiler/tag_switch.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Trivial changes to ignore (or leave unchanged)
	the new field in `du_type'.

compiler/modecheck_unify.m:
	Pass the term__context to unify_proc__request_unify.

compiler/typecheck.m:
	Typecheck the compiler-generated unify predicates for types
	with user-defined equality preds.

compiler/unify_proc.m:
	For d.u. types, if the type has a user-defined equality predicate
	then generate code for the compiler-generated unify predicate
	that just calls the specified predicate, and generate
	code for the compiler-generated compare and index predicates
	that just calls some procedures in mercury_builtin.m that
	report appropriate error messages.
	Ensure that the automatically-generated predicates
	have appropriate term__contexts everywhere, so that if
	the user-defined equality predicate name is ambiguous,
	non-existent, or has the wrong type, mode, or determinism,
	then the error messages from type checking, mode checking,
	or determinism checking refer to the type declaration.

library/mercury_builtin.m:
	Add predicates builtin_index_non_canonical_type/2
	and builtin_compare_non_canonical_type/2, used by
	the code generated by compiler/unify_proc.m.

doc/reference_manual.texi:
	Document the support for user-defined equality predicates.

library/std_util.m:
	Change ML_expand() to return an indication of whether or not
	the type is a non-canonical type (one with a user-defined
	equality predicate).  Change argument/2, functor/2, and
	deconstruct/4 to abort if called for a non-canonical type.

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