Scala:分隔延续解释 - 不
对延续的概念很感兴趣,我开始阅读 wiki、帖子,并看到这个“简单”的例子:
reset {
...
shift { k: (Int=>Int) => // the continuation k will be the '_ + 1' below
k(7)
} + 1
}
// result: 8
如果不了解 Scala,我完全迷失了方向,无法弄清楚 8 是如何产生的。
以下是我试图弄清楚其含义但失败的方法。有谁能给我一个简短的解释吗?是的,有 Scala 语法书,但它们太厚了,我对理解定界延续概念比掌握 Scala 语言更感兴趣......
(Int=>Int)
看起来像一个 C# 委托,输入是 Int,输出是 Int。
<代码>k: (Int=>Int) => k(7)
我在这里迷路了...... k 是什么,(Int=>Int)=>k(7) 是什么?
shift { k: (Int=>Int) =>; k(7) } + 1
更多的迷失...
重置 { ...;移位 { k: (Int=>Int) => k(7) } + 1 }
甚至越来越迷失...
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
Without knowledge of Scala, I'm totally lost here, could not figure out how the 8 comes out.
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)
Looks like a C# delegate, input is Int, output is Int.
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
Even more lost...
reset { ...; shift { k: (Int=>Int) => k(7) } + 1 }
Even even more and more lost...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了 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.
内尔顿,非常感谢! Alex Neth 在链接中的回答帮助了我。现在我想我明白了。让我回答我自己的问题,作为注释。
Reset和Shift的语法:
在C#风格的伪代码中,它实际上意味着:
fotNelton, thanks a lot! Alex Neth's answer in the link helped me out. Now I think I got it. Let me answer my own question to dot down as a note.
Grammar of reset and shift:
It actually means, in C# style pseudo code: