Edd*_*man 11 haskell instance typeclass
我有一个名为的数据类型Praat.我想Praat成为一个实例,Eq以便两个Praats相等,当且仅当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) = ...........
Run Code Online (Sandbox Code Playgroud)
这就是我试图定义实例但它无法正常工作的方式.
-- 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
Run Code Online (Sandbox Code Playgroud)
ham*_*mar 18
instance Eq Praat where
x == y = mx x == mx y
Run Code Online (Sandbox Code Playgroud)
这几乎是你所说的直接翻译.x等于y什么时候mx x == mx y.
| 归档时间: |
|
| 查看次数: |
11997 次 |
| 最近记录: |