我在Haskell的名单上打上了普通类。
class HasEmpty a where
empty :: a
isEmpty :: a -> Bool
class HasEmpty (l a) => List l where
cons :: a -> l a -> l a
uncons :: l a -> (a, l a)
下面是<代码>[:
instance HasEmpty [a] where
empty = []
isEmpty [] = True
isEmpty _ = False
instance List [] where
cons = (:)
uncons (x:xs) = (x,xs)
然而,这产生了一个错误:
Not in scope: type variable a
This is caused by the constraint HasEmpty (l a)
. I am not desperately interested in this particular example, but I am interested in the concept in general. HasEmpty
is a class for types of kind *
, while List
is a class for types of kind * -> *
. Is it possible for me to make a typeclass constraint of a different kind than the typeclass it is constraining?