Overlapping instances in Haskell

前端 未结 2 1233
鱼传尺愫
鱼传尺愫 2020-12-11 16:47

Reading the book Real world Haskell geting below example of Overlapping instances

instance (JSON a) => JSON [a] where
    toJValue = undefi         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 16:55

    These exist

    ghci> :i ToJSON
    ...
    instance ToJSON [Char]
    ...
    instance (ToJSON a, ToJSON b) => ToJSON (a, b)
    

    So there'd be an overlap even if GHC took context into account (see Daniel Fischer's answer).

提交回复
热议问题