Newbie qustion about monads

Alastair Reid alastair at
Thu Oct 2 17:09:11 EDT 2003

Incidentally, it is quite common to define a Monad instance but no Eq 
instance.  (e.g., the IO monad, most parser monads, most state transformer 
monads, etc.)

So you should not interpret the '==' in the monad law as requiring you to 
define an Eq instance.

If you do define an Eq instance, it ought to be reflexive, symmetric and 
transitive (i.e., an equivalence) if you want functions with Eq constraints 
to behave in a meaningful way.

Also, although there's probably no necessity for your Eq instance to match 
your notion of equality between computations (i.e., the == used in the monad 
laws), I think you'll end up very confused if you define an Eq instance which 
doesn't match in the same way that having Eq on pairs ignore the 2nd field 
would confuse you.

Alastair Reid

> So, the question remains: when the monad
> laws say that
>   (return x) >>= f == f x
> what is intended in that "=="? Eq."==" for
>   instance Eq MyCustomMonad where x == y = whatever...
> or a more profound kind of equality?

More information about the Haskell-Cafe mailing list