为什么`changes`返回'Event t(Future a)`

编程入门 行业动态 更新时间:2024-10-09 12:33:01
本文介绍了为什么`changes`返回'Event t(Future a)`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

更改 函数的类型为 Frameworks t =>行为t a - > Moment t(Event t(Future a))。 Future 是抽象的,只有一个函数会使用它( reactimate')。

然而,我可以很容易地写出如下函数: $ $ p $ changes':: Frameworks t => ;行为t a - >时刻t(事件ta)变化'b = fmap(fmap const b< @>)(变化b)

以获得正常(非未来)事件。

有那个功能?如果不是,为什么原始变更函数有更多限制性的类型?

解决方案

函数更改会返回与您描述的函数更改不同的值。关键点如下:

考虑由步进器(或 accumB ),在 t0 时间发生改变。此时行为有什么价值?答案是,行为在所有时间中都具有比变化时间更严格的新值,并且它仍然具有其旧值在时间 t0 。换句话说,更改'函数返回一个事件,其值是更改时行为的旧值。相反,变化函数返回新的(未来)值。由于与递归有关的各种原因,新值被包装在未来 code> type,这样它们才能被访问,直到 reactimate'阶段。

编辑:Tobias已经画出了一张插图:

The changes function has type Frameworks t => Behavior t a -> Moment t (Event t (Future a)). Future is abstract and there is only one function that consumes it (reactimate').

However, I can easily write the following function:

changes' :: Frameworks t => Behavior t a -> Moment t (Event t a) changes' b = fmap (fmap const b <@>) (changes b)

to get a normal (non-Future) event.

Is something wrong with that function? If not, why does the original changes function have a more restrictive type?

解决方案

The function changes returns different values than the function changes' that you describe. The key point is the following:

Consider a Behavior defined by stepper (or accumB), which happens to change at time t0. What value does the Behavior have at this moment in time? The answer is that the Behavior takes on the new value for all times that are strictly larger than the time of change, t > t0, and that it still has its old value at time t0. In other words, the changes' function returns an event whose values are the old values of the Behavior at the time of change. In contrast, the changes function returns the new ("future") values. For various reasons that have to do with recursion, the new values are wrapped in a Future type, so that they cannot be accessed until the reactimate' phase.

EDIT: Tobias has drawn a picture for illustration:

更多推荐

为什么`changes`返回'Event t(Future a)`

本文发布于:2023-11-25 21:25:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Event   Future

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!