2011-12-02 20 views
7

データタイプがPraatです。 PraatEqのインスタンスにして、mxが等しい場合にのみ2つのPraatが等しいとします。どのようにこれを行うのですか?タイプをイクのインスタンスにする方法

-- 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は、mx x == mx yのときyに等しい。

+3

私は 'mx'に'(==) 'と書いていました。 –

関連する問題