Files
mercury/tests/hard_coded/stable_sort.exp
Mark Brown 3b7bf4b7d2 Remove the assumption on user supplied comparison predicates that
Estimated hours taken: 3
Branches: main

Remove the assumption on user supplied comparison predicates that
C(X, Y, =) implies X = Y (similarly for comparison functions).  Our code
shouldn't need to assume this, and sometimes more general orderings are
useful (for example, when you only want to compare the key of a key-value
pair).  The existing assumptions were not documented anywhere, so we now
document the remaining assumptions in builtin.m.

With this assumption gone the issue of the stability of library sorting
predicates that allow a user supplied ordering arises, since elements may
be equivalent according to the ordering even though they are not equal.
Therefore modify the documentation of standard library predicates to make
clear what we do with equivalent elements, and make minor modifications to
the code to ensure that it does as we claim.

Although the builtin comparison predicates are guaranteed to satisfy the
assumption, we nevertheless remove it from the implementation of predicates
in list.m that use builtin comparison.  The rationale for this is that we
don't need the assumption, and it may not be robust if in future we ever
decide to allow user defined comparison.

NEWS:
	Mention the changed assumptions about user supplied comparison
	predicates and functions.

	Mention the new predicate exported from list.m.

library/builtin.m:
	Add types comparison_pred/1 and comparison_func/1, and corresponding
	insts.  Document the assumptions we make about comparison predicates
	and functions.

library/list.m:
	Modify sort/3, sort_and_remove_dups/3, merge/4 and
	merge_and_remove_dups/4, as well as any functional versions, to use
	the new types.  Document the stability of sorting, and modify the
	code to ensure that we conform to this.

	Add remove_adjacent_dups/3, which takes a user supplied comparison
	predicate and determines whether elements are duplicates based on
	this, rather than the usual equality.

	Modify the implementation of some predicates that use compare, to
	avoid the unnecessary assumption.

	Fix some spelling and grammatical errors.

library/array.m:
library/bt_array.m:
	Modify the interface of {,bt_}array__bsearch to use the new types
	and insts.  Update the documentation.

tests/hard_coded/Mmakefile:
tests/hard_coded/stable_sort.exp:
tests/hard_coded/stable_sort.m:
	A test case that checks the stability of list__sort.
2002-09-16 06:07:49 +00:00

2 lines
28 B
Plaintext