Haskell Eq definition that implements the result

I read the definition for Eq typeclass in the data library, and I'm confused. At what point did he realize that the two meanings are equal or not equal. From what I see, it looks like they just call each other infinite.

Defined as follows:

 class Eq a where (==), (/=) :: a -> a -> Bool x /= y = not (x == y) x == y = not (x /= y) 

Could someone explain where it implements the value of Bool ? Do they even call each other or is something else going on?

+6
source share
1 answer

This is the standard implementation of these methods, and yes, it is round. If you use them as-is, youll loop:

 data Foo = Foo instance Eq Foo 
 > Foo == Foo ^CInterrupted 

Circular definitions exist, so you can implement (==) and get (/=) for free, or vice versa:

 data Foo = Foo instance Eq Foo where x == y = True 
 > Foo /= Foo False 

See also the Ord class, which explains that the minimum complete definition in this particular case.

+11
source

All Articles