On 8/17/07, Dan Piponi <[EMAIL PROTECTED]> wrote:
> On 8/17/07, Andrew Coppin <[EMAIL PROTECTED]> wrote:
> > That sounds completely absurd to me... can anybody explain?
> Except...you can switch on ghc's special time travel features...

On reflection I decided my example isn't very convincing. For one
thing, I've argued in another thread that monads aren't really about
sequencing actions. But I concede that there is an exception: the IO
monad. Because the IO monad has observable side effects you can
actually see whether or not an action has taken place at a particular
time, so it really does have to sequence actions. So now consider the
following code:

> import IO
> import Control.Monad.Fix

> test = mdo
>     z <- return $ x+y
>     print "Hello"
>     x <- readLn
>     y <- readLn
>     return z

Evaluate test and you'll be prompted to enter a pair of numbers.
You'll then be rewarded with their sum. But the "Hello" message is
printed before the prompt for input so we know that's being executed
first. And we can see clearly that the summation is performed before
the "Hello" message. So clearly this program is computing its result
before receiving the input.

At this point your natural reaction should be to replace 'print
"Hello"' with 'print z'...
--
Dan
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to