Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.
This repository was 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

Description

@fommil

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions