Making `for` simpler and more regular


#61

I feel that scoping is orthogonal to comprehensions. Mixing them together results in special cases. We see now in for-comprehensions that certain syntactic constructs are illegal, e.g. you can’t do:

for {
  import Foo._

  a <- b
  c <- d
} yield f(a, c)

#62

In most cases, yes. But I still occasionally run into the case of wanting to stick a (collections.breakout) at the end of a comprehension so that the types get massaged into the correct shape.

Some combination of SIP-12 (as in dotty), changing the parse rules to use those of better-monadic-for (is this in dotty yet?), and the 2.13 collections rewrite should make this problem go away


#63

“It’s just syntax” cuts both ways.

scala 2.13.0-M5> for (i <- Option(42) ; i <- Option(3)) yield i
res0: Option[Int] = Some(3)

Probably we lend too much weight to that slogan and also the word “orthogonal”.


#64

No, and this won’t happen until someone writes a SIP for it (and other changes to for-comprehension that can achieve consensus), we’re waiting for the community to do that.


#65

Sorry, I don’t understand your point :slight_smile:


#66

I meant that for translation obscures scoping and is not an orthogonal concern.

Rereading, I see your point was that it should be orthogonal, and that a brace should just introduce a block like anywhere else.

Probably my observation makes more sense as a response to the previous implication that existing syntax expresses scopes clearly.

The topic summary says it has “an estimated read time of 16 minutes .” But that doesn’t include re-reading for context.


#67

Well, say goodbye to that with Scala 2.13 :wink: I already went through my code base and removed in several dozen places … :expressionless: