effekt-lang / effekt-lang/effekt

Missed opts when using multiple resumption to model scope-local, reversible variables

Open
#972 1 comment 0 reactions 0 assignees View on GitHub
optimizer-wishlist
Dominant language
Scala
Stars
469
Forks
41
Avg merge
1d 16h
Merged PRs (30d)
23

Description

Related to #971

[Playground link](https://effekt-lang.org/playground.html?playground=XZDBroMgEEX3fsVd4urlveRtmthF%2F6EfYHVISVAM0lZj%2BPfCADbVDXI4cxmGpKTOQQ2TFvUJF2N0lRktykV2HZUrTJuu1XrdcDP9ekJz5lP4bFU9Scydmeho%2FJTS4qKpAGdXbGEF26IOvx4v5e67nU4%2FHmBpfgyEDdvNx%2FiMASUhepOfUu8%2Bp3N0%2BYKU3rYzD9IzYSee19xKDDzcLpx9UJEzkm2ISCwXxktCn6LmPJ%2BmM7RqDKThxDQqrnm2FkvAv3%2B8nawanR7FkhJDy2X0peko%2F5fNQU%2F9f0Ff%2BTc%3D&repl=bWFpbigp)

The goal of the following code by @marzipankaiser is to (mis)use backtracking & multiple resumption in order to have local operations in a sub-scope that get reverted when we exit the sub-scope:
```scala
effect impl(): Bool
effect exit(): Unit
effect locally{ body: => Unit }: Unit

def scope{ body: => Unit / locally }: Unit =
try {
body()
} with locally {
try {
resume { {b} =>
if (do impl()) {
b()
do exit()
} else ()
}
} with impl {
resume(true)
resume(false)
} with exit { () }
}

def main() = {
scope {
var x = 12
println(x) // ~> 12
do locally {
x = 5
println(x) // ~> 5
}
// now x = 12 again
println(x) // ~> 12
}
}
```

![Image](https://github.com/user-attachments/assets/c18a7467-9f75-4d9c-929f-677ba8e3ffc0)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.