With those definitions, the mutual recursion won't stop - it will recurse infinitely. The idea is that you override one of the two definitions with your own base case when implementing the Eq
typeclass.
So for example if you have a type data Foo = Bar | Baz
your Eq
instance could look like this:
instance Eq Foo where
Bar == Bar = True
Baz == Baz = True
_ == _ = False
Here we only defined ==
, not /=
, so /=
will use its default definition not (x == y)
. However our definition of ==
will not call /=
back, so its no longer mutually recursive and will terminate without problems.
The reason that Eq
provides default implementations for both ==
and /=
is so that you can decide whether you want to provide a definition for ==
or /=
and you get the other one for free even if you choose /=
.