12

I have a data type called Praat. I want Praat to be an instance of Eq so that two Praats are equal if and only if mx are equal. How does one do this?

-- 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) = ...........

This is how I am trying to define the instance but it is not working.

-- 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
Prateek
  • 2,377
  • 17
  • 29
Eddy Freeman
  • 3,207
  • 6
  • 35
  • 55

1 Answers1

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

This is pretty much a direct translation of what you said. x is equal to y when mx x == mx y.

hammar
  • 138,522
  • 17
  • 304
  • 385