[Haskell-cafe] Remember the future

Dan Piponi dpiponi at gmail.com
Sat Aug 18 11:19:49 EDT 2007


On 8/18/07, Andrew Coppin <andrewcoppin at btinternet.com> wrote:

> Surely all this means is that the magical "mdo" keyword makes the
> compiler arbitrarily reorder the expression...?

What mdo actually does is described here:
http://www.cse.ogi.edu/PacSoft/projects/rmb/mdo.pdf

My last example desugars to:

test = mfix (
    \ ~(x,y,z,v) -> do
        z <- return $ x+y
        print "Hello"
        x <- readLn
        y <- readLn
        v <- return z
        return (x,y,z,v))
    >>= \(x,y,z,v) -> return v

So at core there really is a do-expression that's passing 'return $
x+y' into a print which in turn is passed into the 'readLn's.
--
Dan


More information about the Haskell-Cafe mailing list