问题标签 [reactive-banana]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
haskell - reactive-banana 1.0 monadic API:现在如何定义递归行为?
在 reactive-banana <1.0.0 中,这有效:
现在,counter
是根据自身定义的。但是在新的 monadic API 中,accumB
是一个 monadic 函数,这是我看不到如何进行的地方 -Moment
没有MonadFix
实例,那么它现在如何工作?
由于显而易见的原因,这不起作用('不在范围内:计数器')
现在正确的做法是什么?提前致谢!
reactive-banana - 反应香蕉 webkit DOM 样板
是否存在(或者它是否有意义) a reactive-banana
over webkitgtk3
's DOM
?最初我一直在寻找,reactive-banana-gtk
但后来意识到这些小部件过于僵化,我发现没有简单的方法可以从 Haskell 中定义新的小部件。另一方面可以满足我的需求DOM
。css
希望这可以证明用例的合理性。
我需要做什么才能reactive-banana
结束工作Graphics.UI.Gtk.WebKit.DOM
?
我没有在 , 上找到任何东西hackage
,github
也没有通过谷歌搜索找到任何东西。
monads - 如何在反应香蕉中创建一元行为
假设我抓住按键并相应地操作代码缓冲区:
我想创建另一种行为bEval
它将任何代码状态映射到其评估(仅在某些事情真正发生变化时触发)。
但是,评估发生在单子中Interpreter
(hint
从hackage考虑)。我真的可以定义这样的行为bEval
吗?我想我可以Interpreter String
在我的行为中拖拽为状态,累积currentAccumState >>= eval nextEvent
,但我将在哪里runInterpreter
实际强制评估?
编辑:重要的是,这些动作不仅仅是IO ()
而且应该修改某些状态。例如,考虑清除缓冲区/重置计数器/在拉链周围移动。
我的想法是这样的:
我不明白为什么不可能有这样的事情。但是,我也看不到如何在行为中摆脱这种IO
情况:)。
为什么不实际IO
出现在reactive-banana
only中MonadIO
?
haskell - 使用响应式香蕉实现游戏状态
在我的突破实现中,有两个主要行为描述了游戏的主要状态:
两者都是根据tickEvent :: Event t ()
离散更新它们来实现的。
gameOverEvent :: Event t ()
过滤球位置在屏幕下方的所有刻度事件。
我想paddlePosition
用一个新的行为来替换,只要有一个gameOverEvent
,把桨留在原地,伪代码:
第一个问题是:如何newPaddlePosition
使用 reactive-banana 进行表达?
第二个问题有点模糊:根据游戏是否结束来组织整个程序的好方法是什么?还有其他一些考虑,比如:如何处理ballPosition
,如何绘制游戏等等。
reactive-banana - reactive-banana 如何正确执行 IO 事件
基于我之前的问题,我逐渐完善了其设置(如何在反应香蕉中创建单子行为):
假设有eKey
,每当按下某个键时就会触发一个事件,该事件b
的类型Buffer
会在 中发生支持的事件时进行适当修改eKey
,最后IO
对某些事件采取行动。这些IO
操作取决于状态b
(为简单起见,假设它们将当前状态打印b
到控制台)。
目前,我有这个选择事件发生的动作:
然后我做:
对于一些displayBuffer :: IO Buffer -> IO ()
.
它似乎没有按预期工作。bBuffer
似乎重新评估了每个事件的状态(每次事件发生时有效地运行IO
迄今为止收集的所有动作),当我回想起来时,这是有道理的。
我应该如何重构我的代码才能正确地做到这一点?(即IO
动作看到缓冲区的当前状态,除了缓冲区之外什么都没有积累)
如果我可以在适当的事件中构造一个Event
具有值的值,那么我可以简单地将我的专用动作映射到它和. 你怎么看?怎么做?会实现我想要做的事情吗?但是,在我拍摄with的快照以映射它之后,我将如何将当前更改推迟到与当前按键相关联?bBuffer
eKey
IO
reactimate
<@
b
b
<@
Buffer -> IO ()
haskell - Reactive Banana 1.0.0 - Why is this old code breaking?
Here's code that used to work (truncated appropriately I hope)
But now the types have changed.
we have:
makeNetworkDescription :: Parameters -> MomentIO ()
and
accumB :: MonadMoment m => a -> Event (a -> a) -> m (Behavior a)
say I change the definition of bResourceMap
to
slightly off from the accumB
definition, but let's see what happens.
ghc
gives an error
Right, because of the type of accumB
the behavior needs to be within the context of a MonadMoment
. Having a look at MonadMoment
I find two instances
So why did the actual type resolve to Behavior (Behavior ResourceMap)
, the outer type has to be a MonadMoment
, which doesn't match.
I'd like advice on how to resolve this type of problem, it happens with all my Behavior
definitions.
unit-testing - Reactive Banana 1.0.0 - Unit testing in the MomentIO() Monad
Here's an event network sample that I've been using to investigate the behavior of particular monadic actions. I'm wanting a principled approach, rather than this ad-hoc way of testing my code. I know how to test my functions, but I'm looking for best practices for testing Behaviors and Events, given the new design choices in reactive-banana 1.0.0
I'm leaving out a lot, in the hopes I've included only what is necessary to illustrate my problem. Please let me know if there's something missing that should be included to make the problem clearer.
What the buffer is supposed to do, is accumulated player commands (which would then be processed elsewhere), and then be emptied once a particular batch of player commands were processed. Upon the next tick, it happens all over again.
I'm looking to make sure the buffer gets cleared when it supposed to be, and accumulates commands like it is supposed to. Right now, the code works, and I want to write tests to assure it keeps working as I build this game out.
I could make the buffer Behavior
separated from the Event
network in the above example, but what then? What's the best way to get accurate results from the test?
Edit: Update - I believe this link will provide sufficient hints. I'll take a stab at it and report with more details tomorrow.
Edit: Update - I have a unit test written. I will upload to github when it's purty, and then post. The above link was very helpful in sorting out what to do.
Edit: Update - Turns out, if you run stack test and there are type errors, and then you run it again you get output that says your tests have passed. The upshot is, I'm no closer that I was yesterday. I have code and a clearer problem. I may start a different post for that.ct
Edit: Update - I have a test that breaks in a way that is helpful, but I don't what to do about it exactly. I've posted the entire project for context. Below I include just the test code, errors and some discussion.
The problem comes down to accumB
creating a Behavior
in a MomemtIO
. If I have bufferPopulated
return an IO Bool
how can I reconcile that?
Edit: The obvious thing is to write the instance it wants. I think this is probably a red-herring. What do you think. Is this as simple as just writing the MomentIO Bool
instance?
Edit: Update
I think I'm on the right track. I have commented out all test harness code and have changed the signature for bufferPopulated
I believe this should work, but here's the error
Let's take a look at MonadMoment
from Reactive.Banana.Combinators
m
can be any Monad
, IO
is a Monad
. so liftMoment
should lift the Moment Behavior (BufferMap)
to IO Behavior (BufferMap)
, why doesn't it. What's wrong with my reasoning?
haskell - 毫不拖延地从 accumB 获取更新
的文档accumB
说:
注意:与 stepper 一样,行为的值会在事件发生“稍微之后”发生变化。这允许递归定义。
就我而言,没有递归,但我想“立即”获取更新,而不是“稍后”。为什么没有特别版accumB
?我想,我错过了一些明显的东西?
编辑:在我的应用程序中,我有data Config
,它包含各种配置值和一堆Event (Config -> Config)
,当用户在 GUI 中更改某些值时会触发它们。现在,我希望我的程序的其他部分可以随时访问Config
,这就是我在Behavior Config
那里使用的原因。问题是当改变事件被触发时,行为仍然具有旧值Config
,所以我不能立即观察到这种变化。
haskell - 从外部网络采样行为
由于作者已弃用钠,因此我正在尝试将我的代码移植到反应香蕉。但是,两者之间似乎存在一些我很难克服的不一致之处。
例如,在钠中很容易检索行为的当前值:
我看不到如何在反应香蕉中做到这一点
(我想要这个的原因是因为我试图将行为导出为 dbus 属性。可以从其他 dbus 客户端查询属性)
编辑:替换了“民意调查”这个词,因为它具有误导性
haskell - 如何创建一个包含当前刻度值与前一刻度值之间差异的事件?
我正在使用reactive-banana
和sdl2
(使用这个胶水库)进行类似游戏的项目。ABehavior
是为“绝对鼠标位置”创建的,以及为Behavior
“相对鼠标位置”(也就是鼠标移动)创建的。不使用 FRP 时效果很好,但使用 FRP 时,“相对鼠标位置”会成为问题:似乎只有少量数据通过。我怀疑发生这种情况是因为底层的“SDL 事件”(我们用 a 表示Behavior
)没有与 tick Event
s 很好地对齐。
所以我想计算我自己的鼠标移动,只需将当前刻度的鼠标位置与前一个刻度的位置进行比较。我不确定这是否能解决我的问题,但我有很好的希望:)
首先,我不知道如何处理它:State
monad,或 an IORef
,还是reactive-banana
提供另一种方法?
我将摘录我目前拥有的代码:
如上所述,我想mouseMovementE
用mousePositionB
at current tickE
(称为mousePositionE
)和mousePositionE
previous 的值来表达tickE
。
任何帮助是极大的赞赏!