[mercury-users] Type class usage question
Peter Hawkins
peter at hawkins.emu.id.au
Mon Apr 5 12:43:38 AEST 2004
Hi...
On Mon, 5 Apr 2004 11:05 am, Ralph Becket wrote:
> Hi Peter,
>
> yes, unfortunately type classes are not yet quite as easy to use as one
> would like. Once we get around to adding functional dependencies and
> constructor classes this will change. But for now, here's a sketch of
>
> a solution. Part of the trick is to use more than one typeclass:
That fixed my immediate problem. Of course the code is now quite ugly but I
was able to morally cleanse myself with a few '% XXX: This is ugly' comments.
I have another question:
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).
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.
Why? If this is indeed valid why doesn't the compiler accept the (equivalent)
first form?
=)
Peter
--------------------------------------------------------------------------
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