[mercury-users] Type class usage question

Ralph Becket rafe at cs.mu.OZ.AU
Mon Apr 5 14:11:53 AEST 2004

Peter Hawkins, Monday,  5 April 2004:
> What's wrong with this?
> :- module test.
> :- interface.
> :- import_module set.
> :- typeclass foo(C) where [].
> :- instance foo(set(int)) where [].
> :- implementation.
> Compiling this gives:
> Error: expected type in instance declaration to be a functor with variables
> as args: set(int).

The problem with `instance foo(set(int))' is that somewhere else someone
might declare `instance foo(set(T))' making it impossible for the
compiler to resolve which foo method calls should be made for set(int).

> test.m:001: In module `test':
> test.m:001:   warning: module `set'
> test.m:001:   is imported in the interface, but is not
> test.m:001:   used in the interface.
> For more information, try recompiling with `-E'.
> But if I change the instance declaration to this:
> :- type set_of_int == set(int).
> :- instance foo(set_of_int) where [].
> the code compiles.

Ahh, that looks like a compiler bug to me.  Does anyone amongst the
developers think differently?

-- Ralph
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list