[Haskell-cafe] A question about "monad laws"

jerzy.karczmarczuk at info.unicaen.fr jerzy.karczmarczuk at info.unicaen.fr
Mon Feb 11 09:15:51 EST 2008

Deokjae Lee cites: 

> The tutorial "All About Monads" says that "It is up to the programmer to
> ensure that any Monad instance he creates satisfies the monad laws". 
> The following is one of the laws. 
> (x >>= f) >>= g == x >>= (\v -> f v >>= g) 
> However, this seems to me a kind of mathematical identity. If it is
> mathematical identity, a programmer need not care about this law to
> implement a monad. Can anyone give me an example implementation of
> monad that violate this law ?

After three or five reactions to this posting, I think it it is time to

Haskell is not math. 

Or rather, there is no way to be sure that the *implementation* of some
mathematical domains and operations thereupon are fool-proof. Sometimes
you break "en passant" some sacred laws. For example the transitivity of
ordering. 5>2, right? and 8>5 as well. But, imagine a - little esoteric
example of cyclic arithmetic modulo 10, where the shortest distance
gives you the order, so 2>8. 

A mathematician will shrug, saying that calling +that+ an order relation
is nonsense, and he/she will be absolutely right. But people do that... 

There is a small obscure religious sect of people who want to implement
several mathematical entities as functional operators, where multiplication
is f. composition. You do it too generically, too optimistically, and then
some octonions come and break your teeth. 

So, people *should care*. 

Jerzy Karczmarczuk 

More information about the Haskell-Cafe mailing list