我有一个名为 Praat
的数据类型.我要Praat
成为 Eq
的一个实例这样两个 Praat
s 相等当且仅当 mx
是平等的。如何做到这一点?
-- data type
data Praat t = Praat [k] [(k,k,k,k)]
-- praat gives the maximum frequency
Praat t -> Int
mx (Praat [] _) = 0
mx (Praat (e:es) pt) = ...........
这就是我试图定义实例但它不起作用的方式。
-- I want to make Praat instance of Eq so that two Praat are equal
-- when their respective `mx` are equal
instance Eq Praat where
mx :: (Praat k)->Int
(mx k) == (mx k) = True
_ == _ = False
最佳答案
instance Eq Praat where
x == y = mx x == mx y
这几乎是您所说的直接翻译。
x
等于 y
当mx x == mx y
.
关于haskell - 如何使类型成为 Eq 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8351936/