3 ms·
I've heard a bit about delimited continuations [0], like shift & reset [1], and about how superior they are to call/cc, as well as some general reasons why call
by nerdponx 6y ago
I've heard a bit about delimited continuations [0], like shift & reset [1], and about how superior they are to call/cc, as well as some general reasons why call/cc is itself a bad primitive [2].
Any thoughts on delimited continuations with respect to performance? Why aren't more people/languages using them?
0: https://docs.racket-lang.org/more/index.html https://docs.racket-lang.org/more/index.html section 11, "Continuations"
1: http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-e.pdf http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-e.pdf
2: http://okmij.org/ftp/continuations/against-callcc.html http://okmij.org/ftp/continuations/against-callcc.html
- maxiepoo 6y agoThis won't be a very deep answer, but to connect with the original post, programming in CPS is more closely related to delimited continuations than call/cc is because the continuations are just ordinary functions in the host language, unlike call/cc continuations which are a bit more complex. As for why delimited continuations are not more popular, many people find shift/reset a bit difficult to program with. In particular the type systems for them are a bit odd and some variants like prompt/control don't have nice type systems for them. Currently, the closely related notion of (algebraic) effect handlers is quite popular in the functional language design community as something quite similar in expressive power but more intuitive for programming and with very natural typing. The Koka language has a lot of nice introductory resources if you are interested in learning more: https://github.com/koka-lang/koka https://github.com/koka-lang/koka . There's even a serious proposal for adding something based on these to webassembly: https://github.com/effect-handlers/wasm-effect-handlers https://github.com/effect-handlers/wasm-effect-handlers .
- cryptonector 6y agocall/cc can be built entirely out of CPS and closures of indefinite extent (i.e., allocated on the heap). Using CPS with closures of dynamic extent (i.e., allocated on the stack, either explicitly, or because that's all you get, or because the compiler is smart enough to figure out that these closures don't leak out) is a lot more like delimited continuations (but easier to use).