7
的一個實例我有一個名爲Praat
的數據類型。我希望Praat
是Eq
的一個實例,因此當且僅當mx
相等時,兩個Praat
相等。如何做到這一點?如何使一個類型成爲Eq
-- 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
我甚至會在'mx'上寫'(==)' –