Make a newtype instance of Eq



我正在学习Haskell,我得到了以下任务-我有一个由两种混合数据类型组成的newtype,我必须使其成为Eq的实例,而不使用派生。这是我的:

data Number = One | Two | Three deriving Eq
data Character = A | B | C deriving Eq
newtype Combo = Combo ((Character, Character),(Number, Number))
instance Eq Combo where
    Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

然而,拥抱全是

ERROR "testing.hs":5 - Ambiguous class occurrence "Eq"
*** Could refer to: Hugs.Prelude.Eq Main.Eq Main.Eq Main.Eq Main.Eq Main.Eq 

我该如何解决这个问题?我也不能真正导入隐藏的Eq,因为我需要它来检查Number或Character的给定成员是否相等。

更改

instance Eq Combo where
Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

instance Main.Eq Combo where
Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

显然修复了这个错误。

最新更新