【发布时间】:2019-03-08 02:01:18
【问题描述】:
data CouldBe a = Is a | Lost deriving (Show, Ord)
instance Eq (CouldBe m) where
Is x == Is y = x == y
Lost == Lost = True
_ == _ = False
给出错误:No instance for (Eq m) arising from a use of ‘==’
所以:
instance (Eq m) => Eq (CouldBe m) where
Is x == Is y = x == y
Lost == Lost = True
_ == _ = False
工作正常(至少我开始理解错误),但为什么我需要那个约束? 我正在努力学习,所以“为什么”对我来说非常重要。
【问题讨论】:
标签: haskell constraints typeclass