程序员应该可以使用“occs”吗?

发布于 2025-01-05 17:12:31 字数 425 浏览 4 评论 0原文

在阅读和实现 FRP 时,我对 Event 上的 occs 函数的语义感到困惑(在 Conal Elliott 的论文中提到)。处理静态(纯)事件时非常简单,但我不明白它如何处理动态事件(例如按下鼠标按钮等)。例如,如果 occs 返回事件的所有出现,那么据我所知,动态事件的 occs 结果可能是以下内容之一(因为并非所有事件都已知):

  • 调用时已知的事件
  • 自动与事件本身保持同步的数组/列表

当然,这两者看起来都有点难看 - 一个破坏了语义纯度,另一个涉及副作用。

简单地删除 FRP 框架本身之外的 occs 函数(即,将其设为 Event 及其扩展的任何内容的私有函数)是否会更好?只要事件具有返回进一步事件的映射、过滤、合并等功能,我觉得它可能会毫无问题地丢失。或者,我误解了什么吗?

While reading about and implementing FRP I am confused by the semantics of the occs function on Event (referred to in Conal Elliott's papers). It is very simple when dealing with static (pure) Events but I don't understand how it works with dynamic Events (such as mouse button presses etc). For instance, if occs returns all of the occurrences of an Event then as far as I can see a result for occs for a dynamic Event could be one of the following things (since not all occurrences are known yet):

  • The known occurrences at the time of the call
  • An array/list that is automatically kept up to date with the Event itself

Of course both of these seem slightly ugly - one breaks semantic purity and the other involves side effects.

Would it be better to simply remove the occs function outside of the FRP framework itself (ie make it private to Event and anything that extends it)? As long as Event has map, filter, merge etc functions that return further Events I feel it could be lost without trouble. Or, am I misunderstanding something?

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

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

发布评论

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

评论(1

嗼ふ静 2025-01-12 17:12:31

As far as I understand the occs function mentioned in Conal's paper is not part of the API. Rather, it's a specification of the programming model. Conal uses it to describe the semantics of the various combinators, but it's not something that you can or should implement.

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