I'm rather curious on how coroutines are used to i...
# arrow
f
I'm rather curious on how coroutines are used to implement monad comprehensions on Kotlin. I believe I got the overall idea, however I'm failing to see the rationale for this "save and restore": • https://github.com/arrow-kt/arrow-core/blob/master/arrow-core-data/src/main/kotlin/arrow/typeclasses/MonadContinuations.kt#L35https://github.com/arrow-kt/arrow-core/blob/master/arrow-core-data/src/main/kotlin/arrow/typeclasses/MonadContinuations.kt#L37 Does anyone has any pointers to help clarify this? Namely, that save-restore always required? Thanks!
a
that’s the whole keypart and an interesting trick
AFAIK what that does is reset the stack of the continuation in order to emit more than once, which means that in an Fx block, when you bind a List of size N, it’ll execute the code below N number of times
r
We are also working on improving this so we have a separate hierarchy of continuations with faster strategies for strict vs lazy or non deterministic monads like stream or list as Alberto mentioned. So that encoding will change. It's currently a hack with reflection resetting the state across binds.
f
Thanks for answers! I was failing to see the reason for that hack because I forgot that the
flatMap
function can be called multiple times for the same instance (e.g. on the list monad). And the second time it is called, the continuation will already be changed. So I presume that hierarchy will keep the hack for some monad instances and remove it for others, right?