effekt-lang / effekt

A research language with effect handlers and lightweight effect polymorphism

Home Page:https://effekt-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unhelpful error message when boxing blocks

jiribenes opened this issue · comments

The motivation is wrapping a block into a box in order to facilitate a nicer API. (using orElse { ... } { ... } instead of orElse(box { ... }, box { ... }).
I don't quite know whether this is just a bad error message or if it's an actual bug in Typer:

Here's the offending code:

interface OrElse {
  def orElse[T](m1: => T / {} at {}, m2: => T / {} at {}): T 
}

def orElse[T] { m1: => T / {} }{ m2: => T / {} }: T / {OrElse} = {
  do orElse(box { m1 }, box { m2 })
}

which returns the following unhelpful message:
Screenshot 2024-01-12 at 17 52 30

If I just ANF it, I get the same message. When I remove the braces, I get a different error:

interface OrElse {
  def orElse[T](m1: => T / {} at {}, m2: => T / {} at {}): T 
}
def orElse[T] { m1: => T / {} }{ m2: => T / {} }: T / {OrElse} = {
  val f1 = box m1;
  val f2 = box m2;
  do orElse(f1, f2)
}

returns:
Screenshot 2024-01-12 at 17 51 07

I think there are a few different issues here. The first error message is indeed confusing.

However, the second message is expected: you are passing f1 which has capture m1 to the operation which requires an empty capture set.

On a high level: I deeply understand the motivation of avoiding box in the API but I think it's not possible this way.

Maybe we can make it more lightweight by changing syntax somehow

On a high level: I deeply understand the motivation of avoiding box in the API but I think it's not possible this way.

I thought so, but I still wanted to report the confusing error message — dealing with boxing and captures is difficult already.