
18 Jan
2011
18 Jan
'11
10:28 a.m.
Hi Kashyap,
Could someone please help me get a better understanding of the necessity of monads complying with these laws?
Maybe it helps to write them in do-notation. Once written like this, it becomes clear(er?) that do-notation would be much less intuitive if the laws would not hold: Left Unit: return x >>= \y -> f y = f x do y <- return x f y = do f x Right Unit: a >>= \x -> return x = a do x <- a return x = do a Associativity: (a >>= \x -> f x) >>= \y -> g y = a >>= \x -> (f x
= \y -> g y) do y <- do x <- a f x g y = do x <- a y <- f x g y
So, at least, the monad laws ensure that do-notation behaves as one would expect. Sebastian