State of DData

Simon Marlow simonmar at microsoft.com
Fri Mar 26 15:37:47 EST 2004


 
> > Arguably then, anything which is an instance of Monad 
> should be a monad.
> 
> I would certainly argue strongly for that.
> 
> If it ain't true, then small, irrelevant changes in a piece 
> of code could 
> break.  For example, is it safe to make this change:
> 
>   do
>     f y
> ==>
>   do
>     x <- f y
>     return x
> 
> I'd hope it would be.  (And the change might be useful if I 
> want to insert a check or a debugging printf in the code.)

I'm afraid it isn't true that all instances of Monad respect the monad
laws, due to our old friend seq.  See:

http://www.haskell.org/pipermail/haskell/2002-May/009622.html


I don't want this discussion to get out of hand.  The only point I'm
making here is that the Haskell definition doesn't *require* that every
instance of (==) be equality, in the same way that it doesn't *require*
that all Monad instances are monads, and all '+'s are additions etc.

Libraries might rely on properties of these methods, but as far as is
practical those assumptions should be documented.

Cheers,
	Simon


More information about the Libraries mailing list