2011-12-02 41 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'上写'(==)' –

相关问题