3 ms·
You can implement some version of that as long as you have dynamic scope. For simplicity let's just use pseudocode with globals: # By default Yield throws a
by hencq 5y ago
You can implement some version of that as long as you have dynamic scope. For simplicity let's just use pseudocode with globals:
# By default Yield throws an exception
global Yield = function(n) {throw n};
def example() = {
var produce = true;
var n = 0;
while (produce) {
produce = Yield(n)
n = n + 1
}
println("done")
}
# Temporarily set the global Yield to be a different function
with(Yield = function(n) {
println(n);
return n < 3;}) {
example();
}
Where algebraic effects typically differ is that the handler receives a continuation. Potentially you could do more with that than just resume. You could for example store that continuation and build coroutines that way. That makes them essentially the same as delimited continuations. That's something that Common Lisp does not support.
I'm not sure how that works in Effekt though. Since there seems to be a 'resume' keyword they might not be as powerful as delimited continuations.