Allow user-defined comparison functions using the syntax

Estimated hours taken: 10
Branches: main

Allow user-defined comparison functions using the syntax
:- type t ---> t where equality is t_equal, comparison is t_compare.
.
Allow user-defined equality and comparison for foreign types using the syntax
:- pragma foreign_type(c, t, "c_t") where
		equality is t_equal, comparison is t_compare.

compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
compiler/*.m:
	Allow comparison predicates in `type' and `pragma foreign_type'
	declarations

compiler/hlds_data.m:
compiler/*.m:
	Allow equality and comparison predicates to be attached
	to foreign types.

compiler/prog_io.m:
compiler/prog_io_pragma.m:
	Parse the new syntax.

compiler/make_hlds.m:
	Don't add the types to the HLDS or do typechecking if
	there are errors in the type declarations.
	Test case: tests/invalid/foreign_type_visibility.m.

compiler/foreign.m:
compiler/special_pred.m:
compiler/type_util.m:
	Check whether foreign types have user-defined equality.

compiler/unify_proc.m:
	Generate clauses for user-defined comparison,
	and clauses for unification for foreign types.

compiler/intermod.m:
	Resolve overloading before writing the `.opt' files.

library/builtin.m:
	Add `uo' modes for promise_only_solution, for use in
	user-defined comparison predicates.

	Add types and insts to allow declaration of user-defined
	comparison predicates using `with_type` and `with_inst`.
	We already have types and insts `builtin__comparison_pred',
	but they have a different argument ordering to `compare/3'.

NEWS:
doc/reference_manual.texi:
	Document the change.

tests/hard_coded/Mmakefile:
tests/hard_coded/user_compare.{m,exp}:
	Test case.

tests/invalid/Mmakefile:
tests/invalid/typeclass_test_{9,10}.{m,err_exp}:
tests/invalid/purity/purity_nonsense{,2}.{m,err_exp}:
	The change to error-checking in make_hlds.m meant that
	the compilation stopped before some errors in
	typeclass_test_9.m were detected. The code which
	tests for those errors is now in typeclass_test_10.m.
This commit is contained in:
Simon Taylor
2003-02-12 22:58:20 +00:00
parent e701e06c2e
commit 482105e074
35 changed files with 973 additions and 353 deletions

View File

@@ -176,9 +176,9 @@
% VarNames, Foreign Code Implementation Info
; foreign_type(foreign_language_type, tvarset,
sym_name, list(type_param))
sym_name, list(type_param), maybe(unify_compare))
% ForeignType, TVarSet, MercuryTypeName,
% MercuryTypeParams
% MercuryTypeParams, UnifyAndCompare
; foreign_import_module(foreign_language, module_name)
% Equivalent to
@@ -826,7 +826,7 @@
% type_defn/3 is defined above as a constructor for item/0
:- type type_defn
---> du_type(list(constructor), maybe(equality_pred))
---> du_type(list(constructor), maybe(unify_compare))
; eqv_type(type)
; abstract_type.
@@ -846,11 +846,20 @@
:- type ctor_field_name == sym_name.
:- type unify_compare
---> unify_compare(
unify :: maybe(equality_pred),
compare :: maybe(comparison_pred)
).
% An equality_pred specifies the name of a user-defined predicate
% used for equality on a type. See the chapter on them in the
% Mercury Language Reference Manual.
:- type equality_pred == sym_name.
% The name of a user-defined comparison predicate.
:- type comparison_pred == sym_name.
% probably type parameters should be variables not terms.
:- type type_param == term(tvar_type).