typelevel / scala

Typelevel Scala, a fork of Scala
http://typelevel.org/scala/
372 stars 21 forks source link

allow basic assignment as the preamble to a for comprehension #143

Closed fommil closed 6 years ago

fommil commented 7 years ago

When writing Free code, one expects to be able to write entire methods as for comprehensions.

However, the for syntax is limited such that the first line defines the type for the remainder, which means that we cannot put simple assignments in there.

e.g. I'd like to write

for {
  a = pure_function
  b = another_pure
  c <- thing(a, b)
} yield c

but this must be written as (note the extra layer of indentation)

{
  val a = pure_function
  val b = another_pure
  for {
    c <- thing(a, b)
  } yield c
}

or

for {
  a <- Free.pure(pure_function)
  b = another_pure // ok for subsequent assignments
  c <- thing(a, b)
} yield c

It would be really good, and help support cleaner FP style code, if the code I expect to be able to write was rewritten using vals.

This would need to be done in parser, with care taken not to break the RangePositions.

SethTisue commented 7 years ago

this is SI-907, closed as wontfix (by Paul in 2011), but only provisionally closed.

SethTisue commented 7 years ago

incidentally, I don't think this issue tracker is intended for this kind of thing. (if I'm wrong about that, I guess someone from Typelevel will say so, I'm just an onlooker.)

there used to be tons of open issues here for random language improvements/changes like this; they were closed en masse by Miles a while back; see https://github.com/typelevel/scala/issues?q=label%3Adefunct+is%3Aclosed

fommil commented 7 years ago

yeah, I know about the mass closings, I also don't know how the tracker should be used... there is no other space to capture ideas that would be good for FP Scala. I'm using this ticket tracker as a way to put my thoughts down because there is only so much can be discussed in a transitive gitter room (and gitter seems to be very quiet in general these days).

fommil commented 7 years ago

https://github.com/scala/bug/issues/907

dwijnand commented 7 years ago

For general information, for Scala in general the avenue for discussing potential language features/enhancements is a thread on https://contributors.scala-lang.org/.