程序员应该可以使用“occs”吗?
在阅读和实现 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解Conal的论文occs函数> 不是 API 的一部分。相反,它是编程模型的规范。 Conal 使用它来描述各种组合器的语义,但这不是您可以或应该实现的东西。
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.