Monad Maybe?

Simon Marlow simonmar@microsoft.com
Tue, 24 Sep 2002 14:24:47 +0100


> I know this has been written about way too much, but I was=20
> wondering what
> people thought about using 'liftM f' as opposed to '>>=3D=20
> return . f'.  I
> would probably have written Andrew's code using liftM, but I=20
> don't know if
> one is necessarily better than the other.  Does anyone have strong
> thoughts on this?

so, using liftM:

 	(number g >>=3D return . show)

becomes

	(liftM show (number g))

or
	(show `liftM` number g)

but it's important not to get too carried away with abstractions - this
example requires a bit of a trawl around the library documentation for
someone not familiar with liftM.  Personally, unless I was writing
fragments like this a lot, I'd just write it as

	(do r <- number g; return (show r))

Each to his own I suppose.

Cheers,
	Simon