Eddy Freeman
Eddy Freeman

Reputation: 3309

How to make a type an instance of Eq

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

Upvotes: 12

Views: 21135

Answers (1)

hammar
hammar

Reputation: 139930

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.

Upvotes: 21

Related Questions