effekt-lang / effekt-lang/effekt
Unexpected "effect is not allowed in this context" for a list of first-class functions
- Dominant language
- Scala
- Stars
- 469
- Forks
- 41
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 23
Description
The following program claims that `emit[]` is not allowed on the RHS of `for`, but I can't really tell why:
```scala
import stream
def applyAllAndSum(operations: List[(Int) => Unit / emit[Int] at {}], n: Int): Int / {} = sum {
with val op = for[(Int) => Unit / emit[Int] at {}] { operations.each }
// ^^^^^^^^^^^^^^^
// Possible overload: stream::each of type [A](List[A]) => Unit / { emit[A] }
// Effect emit[Int => Unit / { emit[Int] } at {}] is not allowed in this context.
(unbox op)(n)
}
```
Annotating the type of `each` as `operations.each[(Int) => Unit / emit[Int] at {}]` doesn't do anything...
For context, the intended application is something like:
```scala
def addOne(n: Int) = do emit(n + 1)
def monusOne(n: Int) = if (n > 0) { do emit(n - 1) }
def main() = println(applyAllAndSum([box addOne, box monusOne], 0)) // => 1
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.