Scala:定界连续说明-不 [英] Scala: Delimited Continuations Explained - Not
问题描述
我对延续的概念产生了兴趣,我开始阅读Wiki,文章,并来到这个简单"的网站上.例如:
Interested in the concept of continuation, I started reading wikis, posts, and came to this "simple" example:
reset {
...
shift { k: (Int=>Int) => // the continuation k will be the '_ + 1' below
k(7)
} + 1
}
// result: 8
在没有Scala知识的情况下,我在这里完全迷失了方向,无法弄清楚8的表现如何.
Without knowledge of Scala, I'm totally lost here, could not figure out how the 8 comes out.
以下是我试图弄清楚含义但失败的方法.任何人都可以给我一个简短的解释吗?是的,虽然有Scala语法书,但它们太厚了,比起主要的Scala语言,我对理解定界延续概念更感兴趣...
Below is how I tried to figure out the meaning but failed. Any guy could you please give me a short explanation? Yeah there are Scala grammar books but they are too thick, I'm more interested in understanding delimited continuation concept than master Scala language...
-
(Int=>Int)
看起来像C#委托,输入为Int,输出为Int.
Looks like a C# delegate, input is Int, output is Int.
k: (Int=>Int) => k(7)
我在这里迷路了...什么是k,什么是(Int => Int)=> k(7)?
I'm lost here... what is k, and what is (Int=>Int)=>k(7)?
shift { k: (Int=>Int) => k(7) } + 1
更多迷路了...
reset { ...; shift { k: (Int=>Int) => k(7) } + 1 }
甚至越来越多的迷路...
Even even more and more lost...
推荐答案
我发现了Chris League的演讲"Monadologie:焦虑症专业帮助"( http://vimeo.com/13304075 )包含定界延续的更好示例之一.
I found Chris League's talk, "Monadologie: Professional Help for Type Anxiety" (http://vimeo.com/13304075) contains one of better examples of a delimited continuation.
这篇关于Scala:定界连续说明-不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!