I do general class types for lists in Haskell.
class HasEmpty a where empty :: a isEmpty :: a -> Bool class HasEmpty (la) => List l where cons :: a -> la -> la uncons :: la -> (a, la)
To give you an idea of ββhow this works, here are some examples for []
:
instance HasEmpty [a] where empty = [] isEmpty [] = True isEmpty _ = False instance List [] where cons = (:) uncons (x:xs) = (x,xs)
However, this causes an error:
Not in scope: type variable 'a'
This is caused by the HasEmpty (la)
constraint. I am not desperate for this particular example, but I am interested in the concept as a whole. HasEmpty
is the class for view types *
, and List
is the class for view types * -> *
. Is it possible for me to make a typeclass type restriction of a different type than the class it restricts?
source share