没有(Show a)出现的实例

时间:2017-03-29 18:45:23

标签: haskell

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

1 个答案:

答案 0 :(得分:7)

您的instance声明没有上下文。将其重写为instance Show a => Show (Set a)