[m-rev.] for review: use typeclass constraints to help resolve overloading

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 21 18:42:12 AEDT 2002


I agree with David Jeffery's comments.

On 16-Jan-2002, Peter Ross <petdr at cs.mu.OZ.AU> wrote:
> 
> compiler/typecheck.m:
>     When resolving predicate overloading to a typeclass method use the
>     instance declarations to help resolve the overloading.
> 
> tests/hard_coded/typeclasses/Mmakefile:
> tests/hard_coded/typeclasses/overload.exp:
> tests/hard_coded/typeclasses/overload.m:
>     A test case.

There really ought to be some change to the language reference manual
to document what you are trying to implement.

> Actually you have to check both ways: as sometimes the instance type is
> more concrete then the arg type and vice versa.

In that case, you should include some test cases which test both cases.

The test suite should also include some cases using derived instances,
e.g.

		:- instance tc3(list(T)) <= tc(T) where [...].
	vs	:- instance tc4(list(T)) <= tc2(T) where [...].

I'd also like to see a test of the case where the instance
declaration is in another module, e.g.

	:- module m1.
	:- interface.
	:- type t --> t.
	:- typeclass tc(T) where [func f(T) = int].
	:- end_module m1.

	:- module m2.
	:- interface.
	:- import_module m1.
	:- typeclass tc2(T) where [func f(T) = int].
	:- instance tc2(string) where [f(_) = 0].
	:- func bar(t) = int <= tc(t).
	bar(X) = f(X).
	:- end_module m2.

	:- module m3.
	:- interface.
	:- func bar_t = int.
	:- implementation.
	:- import_module m1, m2.
	:- instance tc(t) where [f(_) = 42].	% private
	bar_t = bar(t).
	:- module m3.

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