DEV Community

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

Collapse
 
iquardt profile image
Iven Marquardt

Suspended functions seem to be a replacement for the IO type, not the IO monad. A more idiomatic IO type for Kotlin so to speak. You probably can write a monad instance for suspended functions, but I am not that familiar with Kotlin so I may be wrong.

but are marked as suspend, signaling they need a safe environment to be executed (arrow-fx-coroutines provides such an environment).

This sound like Haskell's main function, which is always of type IO and interprets at runtime what the IO actions mean in the real world.

Collapse
 
eureka84 profile image
Angelo Sciarra

Yeah, the intent is to become more idiomatic.
I don't know much about Haskell (just read a bit "Learn you a Haskell for Great Good" but never actually used it).

Collapse
 
raulraja profile image
Raúl Raja Martínez

Compared to Haskell suspend functions would be like lang special syntax support for something like ContT. But suspension can be generalized to other monads. See the Kotlin std lib SequenceBuilder which is unrelated to IO and builds collections lazily. See also this comment for a more in-depth look into what we are doing dev.to/raulraja/comment/13a8h