【问题标题】:Why does `changes` return `Event t (Future a)`为什么`changes`返回`Event t(Future a)`
【发布时间】:2014-11-17 19:54:48
【问题描述】:

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

但是,我可以轻松编写以下函数:

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

获取正常(非Future)事件。

这个功能有问题吗?如果不是,为什么原来的changes 函数的类型更严格?

【问题讨论】:

    标签: haskell reactive-banana


    【解决方案1】:

    函数changes 返回的值与您描述的函数changes' 不同。关键点如下:

    考虑由stepper(或accumB)定义的行为,它恰好在时间t0发生变化。行为此时此刻有什么价值?答案是,对于所有 严格大于更改时间 t > t0 的时间,行为都采用新值,并且它仍然具有旧值在时间 t0。换句话说,changes' 函数返回一个事件,其值是更改时 Behavior 的旧值。相反,changes 函数返回新的(“未来”)值。由于与recursion 有关的各种原因,新值被包装在Future 类型中,因此直到reactimate' 阶段才能访问它们。

    编辑:Tobias 画了一张图片作为说明:

    【讨论】:

    • 从答案链接到它。 :-)
    猜你喜欢
    • 2015-09-22
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多