[Haskell-cafe] Re: evaluation semantics of bind

Jake McArthur jake at pikewerks.com
Thu Feb 5 12:42:32 EST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gleb Alexeyev wrote:
| Perhaps my example doesn't work, so I'll try another example.
| As you know, (>>=) is just an (overloaded) higher-order function.
| Let's consider another higher-order function, map. The expression
|  > map (\x -> 42) [1..3]
| evaluates to [42, 42, 42].
| As you can see, the function (\x -> 42) passed to map ignores its first
| argument. Would you expect the compiler to discard the call to map?

In fact, this can even be rewritten with bind:

~    [1..3] >>= \x -> return 42

So if you wouldn't expect the map to be discarded, certainly the bind
should not be either.

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

iEYEARECAAYFAkmLJQgACgkQye5hVyvIUKlUNQCgp6T0BCs00rYS3ygprs5rs3VM
mrgAoMo1AgLTTeosXV8dQa+1BljcpfQy
=o3iZ
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list