Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

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

Closed
fommil opened this issue Apr 2, 2017 · 5 comments
Closed

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

fommil opened this issue Apr 2, 2017 · 5 comments

Comments

@fommil
Copy link

fommil commented Apr 2, 2017

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
Copy link
Member

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

@SethTisue
Copy link
Member

SethTisue commented Apr 2, 2017

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
Copy link
Author

fommil commented Apr 2, 2017

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
Copy link
Author

fommil commented Apr 25, 2017

scala/bug#907

@dwijnand
Copy link

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

@fommil fommil closed this as completed Aug 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants