Introduction, comprehensions beyond arrays
metaweta at gmail.com
Sun May 12 11:36:41 PDT 2013
On Sat, May 11, 2013 at 11:34 PM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
> In addition to what Brendan said about the cost of actually generating
> nested arrays in the common case, I don't think this desugaring does
> what you want - if you have only a single for-of, you'll just get an
> array back out, without a chance to call the custom flatten on it.
> You can't handle this generically, either, because the innermost
> for-of is handled as a map rather than a flatMap.
That's intentional. As I wrote, for-of would bind functions of the
form A->[TB], not A->TB.
> You really do need
> to go monadic all the way, and as Brendan said, that's too much cost
> for the common case of Arrays.
There's a way to accomplish it that wouldn't require creating new
arrays, but the flatten operation becomes far less intuitive and loses
a lot of the attractiveness of a special syntax. It's essentially
inserting a "reified comma" for each loop.
> Let's just add do-expressions, or something similar, in the future.
> We can leave list comprehensions to their array specialization for
Mike Stay - metaweta at gmail.com
More information about the es-discuss