Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected "effect is not allowed in this context" for a list of first-class functions #727

Open
jiribenes opened this issue Dec 7, 2024 · 1 comment
Labels
area:typer bug Something isn't working

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Dec 7, 2024

The following program claims that emit[<first-class function type>] is not allowed on the RHS of for, but I can't really tell why:

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:

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
@jiribenes jiribenes added the bug Something isn't working label Dec 7, 2024
@jiribenes
Copy link
Contributor Author

jiribenes commented Dec 7, 2024

I can't even write a "monomorphized" version of for:

def myfor { stream: () => Unit / emit[(Int) => Unit / emit[Int] at {}] } { action: ((Int) => Unit / emit[Int] at {}) => Unit }: Unit / {} =
  try {
    stream()
    // ^
    // Effect emit[Int => Unit / { emit[Int] } at {}] is not allowed in this context.
  } with emit[(Int) => Unit / emit[Int] at {}] { value =>
    resume(action(value))
  }

... is it because of the "nested" effect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant