2011-12-02 68 views
7

的一個實例我有一個名爲Praat的數據類型。我希望PraatEq的一個實例,因此當且僅當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 

回答

14
instance Eq Praat where 
    x == y = mx x == mx y 

這是非常你所說的直接轉換。 x等於ymx x == mx y

+3

我甚至會在'mx'上寫'(==)' –

相關問題