ghci给了我错误"因使用' commaSeperated'"
而没有(显示a)的实例我想要做的是为我的数据集定义一个使用花括号而不是方括号的节目。我在这里做错了什么?
data Set a = Set [a]
instance Show (Set a) where
show (Set a) = "{" ++ init (commaSeparated a) ++ "}"
commaSeparated :: Show a => [a] -> [Char]
commaSeparated [] = ""
commaSeparated (x:xs) = show x ++ "," ++ commaSeparated xs
答案 0 :(得分:7)
您的instance
声明没有上下文。将其重写为instance Show a => Show (Set a)
。