阅读歌厅例如重叠的情况下书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的实例。
感谢您的非常详细的解释 –
顺便说一句:稍后的书指出,你可以使用'OverlappingInstances'杂注来“解决”在这个答案中描述的“问题”。就我个人而言,我不明白为什么它是这样的......希望有一天我会饶舌它。 – Brendan