Replies: 4 comments
-
Does Effekt have some way to express mutable parameters? I've finally wrapped my head around #108 and was able to implement def next[T]() {mut self: => Unit / Yield[T]}: Option[T] = {
try {self(); None()} with Yield[T] {
def yield(x) = {
self = fun() { resume(()) }
Some(x)
}
}
} def peek[T]() {mut self: => Unit / Yield[T]}: Option[T] = {
try {self(); None()} with Yield[T] {
def yield(x) = {
self = fun() { yield(x); resume(()) }
Some(x)
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I suppose this doesn't actually make very much sense with "computations" being distinct from "values"... hmm. Unless instead of yielding values directly a |
Beta Was this translation helpful? Give feedback.
-
Hey, sorry for the late response. We have multiple examples of "mutable continuations" hidden somewhere in this repo. For instance here: https://github.com/effekt-lang/effekt/blob/master/examples/benchmarks/other/generator.effekt or in a variation also here: effekt/examples/casestudies/scheduler.effekt.md Lines 38 to 61 in a41dde5 and in the issue (#108) that you linked. Currently computation is always considered immutable, while for values we have |
Beta Was this translation helpful? Give feedback.
-
We have just merged #527 (thank you for your comments on that one). It contains a function
and takes a stream that pushes values with
The ability to read values is only available in a limited scope, because we allocate the mutable variable All that said, we are very happy about feedback on this issue and in general. |
Beta Was this translation helpful? Give feedback.
-
I've been trying to figure out how to implement something like Rust's
.next()
and.peek()
explicit-iterator methods effectfully.In the fake language I've been using to prototype things before implementing them in Effekt, considering continuations as first-class values that are mutated by
.resume()
and can be assigned to seems to allow for semantics compatible with both effectful, lazy iterators and also explicit.next()
and.peek()
methods. That linearity / ownership is preserved seems very hard to deal with (but possible?? i saw a recent paper) but also not super relevant for the main conceptual issue I'm hitting.But this is very far from Effekt's semantics... since there isn't an explicit Continuation type, and instead computations that are treated as zero-arity functions when passed to a function through a
{}
block, and are called as a standard function instead of with.resume()
, with the target of theresume
keyword instead implicit in the effect handler. So I'm kind of wondering, is this sort of thing possible to express in Effekt? Are there different features of Effekt's effect-and-handler system that I haven't stumbled across that might be relevant here? Or is this entirely the wrong approach to the issue, conceptually, and does something like.next()
and.peek()
necessitate operating on some concrete iterator struct?Beta Was this translation helpful? Give feedback.
All reactions