State of DData

Alastair Reid alastair at
Fri Mar 26 15:00:28 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:

    f y
    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.)

But if Monads don't have to satisfy this axiom, then I can't make a change 
like this without having to write additional conditions in the documentation 
or know all possible instances of the code.

> And '+' should be addition.  etc. etc.

I think it is well accepted that addition in computers is rarely commutative, 
associative, etc. across the whole range of values.

> Haskell doesn't require any of these to be true, and similarly it
> doesn't require that every instance of '==' is equality.

Though it is, perhaps, worth noting that all standard instances of Eq use 
observational equality which is plain, ordinary equality for normal values 
and, if we look at the common extensions, is 'pointer equality' for mutable 
objects like IORefs.

(For abstract datatypes like balanced binary trees, the appropriate equality 
would probably be to test whether the trees contain the same set of values 
even if they are balanced slightly differently.)

Alastair Reid

More information about the Libraries mailing list