DEV Community

Discussion on: IO: to be a Monad or not to be, that's the question!

Collapse
 
iquardt profile image
Iven Marquardt • Edited

You write that Kotlin can avoid monadic nesting in some/many cases using delimited continuations based on suspend functions. I am currently researching on this topic in the JS context, where we have generator functions. The problem is that such functions can only resume once at a specific position, but to flatten monadic computations in general we'd need multi-shot continuations. How do you solve that in Kotlin? Are Kotlin suspened functions multi-shot? Maybe you can provide some external resources?

Collapse
 
iquardt profile image
Iven Marquardt • Edited

Think I answered my own q: The Kotlin compiler performs a CPS transformation under the hood, similar to Haskell's do block transformation to nested >>=.

Thread Thread
 
raulraja profile image
Raúl Raja Martínez

yes and while multishot is not supported since they are single-shot delimited, you can still multi prompt and build multi-shot like continuations with it.