Newbie question about classes and class parameters

Let's say we have infamous Set class defined this way:
class Set s a where empty :: s a isEmpty :: s a -> Bool
Lets also say that we could define sets as lists:
data SetAsList a = SL [a] deriving (Eq,Ord,Show) instance Set SetAsList a where empty = SL [] isEmpty (SL []) = True isEmpty _ = False
So far, so good. Lets define type synonim for set of integers:
type IntegerSet = SetAsList Integer
And set of sets of integers:
data IntegerSuperSet = ISS (SetAsList IntegerSet)
Testing in Hugs show that everything seems to be working: Main> :t ISS (SL [ (SL [1,2,3])::IntegerSet, (SL [4,5,6])::IntegerSet ]) ISS (SL [SL [1,2,3],SL [4,5,6]]) :: IntegerSuperSet However: Main> isEmpty (ISS (SL [(SL [1,2,3])::IntegerSet, (SL [4,5,6])::IntegerSet])) ERROR - Type error in application *** Expression : isEmpty (ISS (SL [SL [1,2,3],SL [4,5,6]])) *** Term : ISS (SL [SL [1,2,3],SL [4,5,6]]) *** Type : IntegerSuperSet *** Does not match : a b This is completely understood - I need to state that IntegerSuperSet is an instance of Set for isEmpty to be working. But:
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? -- Dmitry Astapov //ADEpt E-mail: adept@umc.com.ua Information Systems Expert Office: +380-50-110-3876 Ukrainian Mobile Communications Mobile: +380-50-330-2019 GPG KeyID/fprint: F5D7639D/CA36 E6C4 815D 434D 0498 2B08 7867 4860 F5D7 639D

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
participants (2)
-
Dmitry Astapov
-
Frank Atanassow