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

Jake McArthur jake at pikewerks.com
Thu Feb 5 15:32:49 EST 2009

Hash: SHA1

mail at justinbogner.com wrote:
| 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

That the order does not matter is definitely not an implementation
detail. Order not mattering is exactly what declarative programming is
about. The semantics of the above expression are the same as this:

~    (<$> [0..9]) . (,) =<< [0..]

There is no "do X and then do Y," only "this is what I want."
Declarative semantics. As I said, just because do notation makes it look
imperative doesn't mean it actually is.

| 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.

It can be helpful sometimes, but I don't think it should be the standard
way to think of bind. There are too many cases when it makes little
sense as a sequencing operator.

- - Jake
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the Haskell-Cafe mailing list