[Haskell-cafe] return in Monad class necessary?

Neil Mitchell ndmitchell at gmail.com
Mon Nov 26 20:30:24 EST 2007


Hi Henning,

> I wonder whether it is a typical mistake of beginners
> to write 'return' within a do-block (that is, not at the end)
> and if it is possible to avoid this mistake by clever typing.

There are legitimate uses of return inside a do, see:
http://www.cs.york.ac.uk/fp/darcs/catch/catch_1/Analyse/Fix.hs

The code has a bit like:

            x <- return $ apply x addReq (\y -> y{requiredBy =
Set.insert k (requiredBy y)})
            x <- return $ apply x delReq (\y -> y{requiredBy =
Set.delete k (requiredBy y)})

i.e. modify x, which you can't do with let's because of the scoping
(they are really let-rec's). I often use return to do binding and name
shadowing in do blocks.

Having said that, when I was learning Haskell, I didn't know you could
put let in a do block, and did use the return for all variables!

Thanks

Neil


More information about the Haskell-Cafe mailing list