Newbie question about classes and class parameters

Frank Atanassow franka@cs.uu.nl
Wed, 17 Oct 2001 14:49:53 +0200


Dmitry Astapov wrote (on 17-10-01 11:25 +0300):
> Let's say we have infamous Set class defined this way:
> 
> > class Set s a where
> >   empty   :: s a
> >   isEmpty :: s a -> Bool
[..]
> > instance Set IntegerSuperSet where
> >   empty = ISS (SL [])
> >   isEmpty (ISS (SL [])) = True
> >   isEmpty _ = False
> 
> gives me:
> Reading file "/tmp/bug.lhs":
> ERROR /tmp/bug.lhs:38 - Wrong number of arguments for class "Set"
> 
> Obviously I am missing something very important here. Could someone enlighten me?

First, the class declaration defines Set as having two parameters, s and a. In
an instance declaration, you must supply types for both. So:

instance Set IntegerSuperSet Integer where
  ...

would be correct, except for the second problem, which is that in Set s a, s
is actually type constructor (of kind * -> *), while the argument which you
try to supply for s, namely IntegerSuperSet, is a type constant (of kind
*). So there is a kind mismatch. Try this instead:

  data SuperSet a = SuperSet (SetAsList a)

  instance Set SuperSet a where
    ...

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379