[Haskell-cafe] Re: Bind as a sequencing operator
wagner.andrew at gmail.com
Thu Feb 5 15:38:34 EST 2009
bind is no more a sequencing operator than function composition is. Just as
the order in which you pass two functions (ignoring the type issue for the
moment) matters, the order in which you pass things to bind matters. The
sense in which the order _doesn't_ matter is that of the order in which what
you pass gets evaluated.
On Thu, Feb 5, 2009 at 3:32 PM, Jake McArthur <jake at pikewerks.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> 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
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> -----END PGP SIGNATURE-----
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe