我正在尝试使用haskell声明一个实例,这里我有我的数据类型:
data Classification = Aproved Int
| Denied
| Missing
deriving (Show)
实例宣布:
instance Eq Classificacao where
Denied == Denied = True
Missing == Missing = True
Aproved x == Aproved y = y==x
当我尝试比较数据构造函数时,如果我在GHCi Denied==Missing
使用
我该怎么办?我还在学习。
答案 0 :(得分:9)
添加最终模式匹配以测试任何其他输入组合为False
,如下所示:
instance Eq Classification where
Denied == Denied = True
Missing == Missing = True
Aproved x == Aproved y = y==x
x == y = False