effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

Direct access to handlers/state #645

Closed serkm closed 1 month ago

serkm commented 1 month ago

Alternative to #636. The meta-stack now stays movable and only prompts have a stable address.

serkm commented 1 month ago

Here is a minimal example where this branch shines. On master, you can observe it slowing down, while this branch stays fast.


effect E(): Unit
effect F(i: Int): Unit

def f(i: Int): Unit / F = {
  try {
    do F(i);
    if (i != 0) {
      f(i - 1)
    }
  } with E {
    resume(())
  }
}

def main() = {
  try{
    f(1000000)
  } with F { (i: Int) =>
    println(i)
    resume(())
  }
}