Hi, I’m trying to implement a simple inference engine for stochastic programming using the new coroutine support, à la webppl. I need to be able to call
resume on continuations multiple times (each time certain suspended functions are called), which is not currently supported. The documentation states:
However, first-class continuations can be implemented as a separate library by cloning the state of the coroutine that is captured in continuation, so that its clone can be resumed again. This mechanism may be efficiently provided by the standard library in the future.
Is there an example I can follow for this?
CoroutineImpl and other related classes have private state that I don’t know how to clone. How much of the existing library do I need to duplicate & tweak to get it working? Does this require modifying the compiler? I did try calling
suspendCoroutineOrReturn multiple times in a suspension to create multiple continuations, but the way CoroutineImpl currently works leads to some very very strange results…