异步 F# 与 CCR 框架

发布于 2024-08-31 16:27:30 字数 258 浏览 1 评论 0原文

阅读有关 CCR 的内容后: http://www.infoq.com/news/2008/12 /CCR 我的印象是它的功能与 F# 异步块几乎完全相同?

您产生 port.Receive 和 port.Test 以便执行与“let!”相同的操作。

这是正确的吗? CCR 中是否有 F# 异步无法提供的优势?

After reading about CCR : http://www.infoq.com/news/2008/12/CCR
I get the impression that it does pretty much exactly the same as F# async blocks?

You yield port.Receive and port.Test in order to do the same as "let!".

Is this correct?
And are there any benefits in CCR that you don't get with F# async?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清旖 2024-09-07 16:27:30

您提到的文章中的示例实际上看起来就像异步工作流程中的 let! 。一般来说,C# 中的 yield return 关键字可以对类似于 F# 计算表达式的模式进行编码(以一种奇怪的方式,因为它是为创建枚举器而设计的):

  • AsyncEnumerator,(恕我直言)比 CCR 简单,并且更接近 F# 异步 我写
  • 一篇文章,更详细地解释了这种相似性。

我认为 CCR 和 F# 异步工作流程之间的主要区别在于 CCR 还包含用于消息传递并发性的库。例如,请参阅本文 - 它使用端口 类(您可以向端口发送消息)和 Arbiter.Receive,这是一个允许您等待来自 Port 的消息的原语。

在 F# 中,您可以使用 MailboxProcessor 来实现相同的消息传递通信模式,但这不是 F# 异步工作流的内置部分 - MailboxProcessor 是实现的 < em>使用异步工作流程。

总结:我认为 F# 异步工作流程更简单,概念更清晰。然而,CCR 和异步工作流程与 MailboxProcessor 一起实现了大致相同的编程模式。

The example in the article you mentioned really looks just like let! from asynchronous workflows. In general, the yield return keyword in C# makes it possible to encode patterns similar to F# computation expressions (in a weird way, because it was designed for creating enumerators):

  • This is also used by AsyncEnumerator, which is (IMHO) simpler than CCR and a bit closer to F# asynchronous workflows
  • I wrote an article that explains this similartiy in more details.

I think that the key difference between CCR and F# asynchronous workflows is that CCR also includes libraries for message-passing concurrency. See for example this article - it uses Port class (you can send messages to ports) and Arbiter.Receive, which is a primitive that allows you to wait for messages from Port.

In F#, you can use MailboxProcessor for implementing the same message-passing communication pattern, but this isn't a built-in part of F# asynchronous workflows - MailboxProcessor is implemented using asynchronous workflows.

In summary: I think that F# asynchronous workflows are simpler and conceptually clearer. However, CCR and asynchronous workflows together with MailboxProcessor implement roughly the same programming pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文