[Haskell-cafe] Re: Bind as a sequencing operator

mail at justinbogner.com mail at justinbogner.com
Thu Feb 5 14:56:58 EST 2009


Jake McArthur <jake at pikewerks.com> writes:
> The problem with your description is that you said "and then." The
> result will be generated lazily. There is no sequencing here. Consider:
>
> ~    do x <- [0..]
> ~       y <- [0..9]
> ~       return (x, y)
>
> Which list is generated first?
>

This is an implementation detail, since y has no dependency on x the
compiler's free to reorder instructions, as it would be an imperative
language. Semantically this means do x and then y, since if y is changed
to depend on x, this is still valid, but if x is changed to depend on y,
this sequence is not valid.

Just because the compiler is allowed (and even encouraged) to change the
sequence where that won't change the results, considering this a
sequence is still valid and meaningful.

> | As for Reader, I don't know enough about it to say anything.
>
> Reader provides an immutable value that can be retrieved at any point in
> the monad. There are no monadic side effects, so it doesn't really mean
> much to say that anything happens in any particular order.
>

It still needs to be retrieved (logically, not necessarily temporally)
before it's used, doesn't it?

> - Jake



More information about the Haskell-Cafe mailing list