假设我有以下数据结构:
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
在最后一条语句中,我试图为我的类型类创建通用实例,我假设类型“a”是 Int 或 String,但编译器不满意:
`Dezi' is applied to too many type arguments
In the instance declaration for `TestInterface [a]'
我是初学者,仍在学习过程中。
谢谢!