限定継続
delimited continuation
部分継続、partial continuation
継続は、一度呼び出されると元のところに戻ってこない
未来永劫の計算を全て取ってくる
そのため、扱いづらい
限定継続は、ある区切りのところまで処理を進めた後に、呼び出し元に戻る
未来永劫ではなく、扱う未来を限定している
https://gyazo.com/eda8463f13076f594e6a7b578ec4ac5f
限定継続を取ってくる命令など
shift/reset
control/prompt
cupto/prompt
bshift/breset
gshift/greset
これら2つの関数はペアで使用される
個々のペアごとに型付けのしやすさなどの扱いやすさが異なるらしい
限定継続を使える言語の例
primitiveな機能として提供されている
Racket
Carbon (experimental)
OchaCaml
Gauche
Haskell
Control.Monad.CC
https://hackage.haskell.org/package/CC-delcont-0.2.1.0/docs/Control-Monad-CC.html
2020にproposalが出ている ref
関連
限定継続モナド
参考
『shift/resetプログラミング入門』
めちゃくちゃわかりやすい
https://en.wikipedia.org/wiki/Delimited_continuation
/haskell-shoen/限定継続
https://stackoverflow.com/questions/29838344/what-exactly-is-a-continuation-prompt
図解
#WIP
Racketには以下のような関数があり、それらを組み合わせることで限定継続できる ref
make-continuation-prompt-tag
call/prompt
call/comp
abort/cc
https://blog.miz-ar.info/2022/10/delimited-continuations/
https://zenn.dev/mod_poppo/articles/delimited-continuations-in-lua
answer type modification
@lotz84_: GHCの次のバージョンから採用される限定継続のプリミティブを使って Algebraic Effects のライブラリを1から作るチュートリアル的な記事。限定継続の使い方が参考になりそう📝/
From delimited continuations to algebraic effects in Haskell
https://t.co/FSd8nsP5S1