加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

不明白Scala分隔延续的打字(A @cpsParam [B,C])

发布时间:2020-12-16 09:44:33 所属栏目:安全 来源:网络整理
导读:当一个值类型为A @cpsParam [B,C]以及在使用分隔的连续工具时,我应该为我的值分配什么类型的表单时,我正在努力地了解这是什么意思。 我看了一些消息来源: http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf http://www.scala-lang.org/node/2096 htt
当一个值类型为A @cpsParam [B,C]以及在使用分隔的连续工具时,我应该为我的值分配什么类型的表单时,我正在努力地了解这是什么意思。

我看了一些消息来源:

http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf

http://www.scala-lang.org/node/2096

http://dcsobral.blogspot.com/2009/07/delimited-continuations-explained-in.html

http://blog.richdougherty.com/2009/02/delimited-continuations-in-scala_24.html

但他们并没有给我很多的直觉。在最后一个链接中,作者试图给出明确的解释,但是还不够清楚。

The A here represents the output of the computation,which is also the input to its continuation. The B represents the return type of that continuation,and the C represents its “final” return type—because shift can do further processing to the returned value and change its type.

我不明白“输出计算”,“延续的返回类型”和“延续的最终返回类型”之间的区别。他们听起来像同义词。

解决方法

所以,人们帮助我在别的地方。这里是答案:

reset ({
    ...
    ...shift((k:A=>B) => ...::C)::A...
    ...
}::B)::C

所以,shift是类型B的计算{…}中类型A的一个孔。shift的参数返回一个类型C的值,这就是为什么reset({…})具有类型C.

了解这些东西的关键在于看到{…}并重新设置{…}具有??不同的类型,具体取决于shift的参数返回的类型。

例如:

reset ({
    "number "+shift((k:Int=>String) => List(k(1),k(2),k(3)))
})

返回列表(“1”,“2”,“3”)。

这里A是Int,B是String,C是List [String],因为{“number”_}是(这里)一个int到String的函数和shift的参数,给定该函数产生一个List [String],其中成为复位的结果({…})。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读