Apologies again, I'm a beat or three behind today. I think you gave the example already:

  expr1.flatMap(x =>
    expr2(x).flatMap(y =>  ...
      exprN(x, y, ...).map(z =>
        result(x, y, ..., z)
      )
    )
  )

Nice when Scala and JS look alike!

I don't think we'd make comprehensions return a monad, specifically a Promise, even if we had the silly things (Promises, I mean -- just teasing about monads) in the language.

JS is eager and mutational. Although Mark and I have discussed privately trying to get E-like "featureless" promises, which become their fulfillment value, we think it's too big a stretch. Especially in light of existing libraries, but even starting fresh.

Without E-like featureless/"becoming" promises, I wouldn't foist them on syntax for eager computations such as comprehensions and generator expressions.

So is the explicit functional style, with arrows for sugar, really too much?

/be

Brendan Eich wrote:
Brendan Eich wrote:
Mike Stay wrote:
On Fri, May 10, 2013 at 1:07 PM, Brendan Eich<[email protected]> wrote:
What's wrong with the iteration protocol?

Nothing at all for arrays.  For every other monad, there's no sugar:
the only monad multiplication that's supported is list concatenation.

Iteration is much more general than "arrays".


Oh, sorry -- you mean comprehensions (not the iteration protocol, which is used by all for-of syntax) are only about creating fresh arrays.

Yes, that's true. One alternative is a generator expression, which doesn't build any eager data structure, rather iterates and yields values on demand.

As Jason pointed out, arrows sweeten the explicit monadic patterns, e.g. monadic Promises. To close this thread it would be helpful to see an example where you use all the ES6 sugar, and then say why you'd still want another special form.

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to