[m-rev.] for review: user-defined comparison

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 12 15:51:11 AEDT 2003


On 12-Feb-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> +A comparison predicate can also be supplied.
> +
> + at example
> +:- type set(T) ---> set(list(T))
> +        where equality is set_equals, comparison is set_compare.
> +
> +:- pred set_compare(comparison_result::uo, set(T)::in, set(T)::in) is det.
> +set_compare(promise_only_solution(set_compare_2(Set1, Set2)), Set1, Set2).
> +
> +:- pred set_compare_2(set(T)::in, set(T)::in,
> +                comparison_result::uo) is cc_multi.
> +set_compare_2(set(List1), set(List2), Result) :-
> +        compare(Result, list__sort(List1), list__sort(List2)).
> + at end example

Here the code uses "compare" without defining it.
What's "compare"?

(The code also uses `list__sort', but since that name is module-qualified,
it's easier for the reader to guess that this is a predicate from
another module, perhaps from the Mercury standard library.
With `compare', there is no such clue.)

> +A type declaration for a type @samp{foo(T1, @dots{}, TN)} may contain a
> + at samp{where comparison is @var{comparepred}} specification only it declares

s/only it/only if it/

> +The semantics [...] are as follows:
...
> +Any comparisons of type @var{T} are computed using the specified predicate
> + at var{comparepred}.

Any comparisons?  What's a comparison?  When do they occur?

I think this needs to be spelt out a lot more clearly.

Remember that the reader will probably read the language reference manual
before the library reference manual, so you can't assume that the reader
knows anything about the Mercury standard library.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list