Let's say I have following data structure:
data Dezi = Dezi1 Int | Dezi2 String | Dezi3 [Dezi] deriving(Show)
class TestInterface a where
testInt :: a -> Dezi
instance TestInterface Int where
testInt 0 = Dezi1 0
testInt _ = Dezi2 "Nie nula"
instance Dezi a => TestInterface [a] where
testInt xs = Dezi3 $ map (\x -> testInt x) xs
In last statement I'm trying to create generic instance for my type class I asume that type 'a' is Int or String, but compiler is not happy:
`Dezi' is applied to too many type arguments
In the instance declaration for `TestInterface [a]'
I'm beginner and still in learning process.
Thanks!
Dezi
is a datatype, not a typeclass. Types aren't "instances of Dezi
". Instead you might say something like
instance TestInterface a => TestInterface [a] where
testInt xs = Dezi3 $ map testInt xs
This reads like "to make a list of a
s an instance of TestInterface
, look up the instance for a
and use that."