阅读本书Real world Haskell
得到以下重叠实例的示例
instance (JSON a) => JSON [a] where
toJValue = undefined
fromJValue = undefined
instance (JSON a) => JSON [(String, a)] where
toJValue = undefined
fromJValue = undefined
ghci> toJValue [("foo","bar")]
<interactive>:1:0:
Overlapping instances for JSON [([Char], [Char])]
arising from a use of `toJValue' at <interactive>:1:0-23
Matching instances:
instance (JSON a) => JSON [a]
-- Defined at BrokenClass.hs:(44,0)-(46,25)
instance (JSON a) => JSON [(String, a)]
-- Defined at BrokenClass.hs:(50,0)-(52,25)
In the expression: toJValue [("foo", "bar")]
In the definition of `it': it = toJValue [("foo", "bar")]
据我了解,这不会是重叠的,因为 [a] 不应该是一个选择,因为对 JSON [a] 的限制是“a”必须是 JSON 的实例本身。(String, a) 没有 JSON 实例。