gpt4 book ai didi

haskell - 来自行为的元素(功能响应式(Reactive)编程)

转载 作者:行者123 更新时间:2023-12-02 00:02:11 25 4
gpt4 key购买 nike

我只是想开始使用 FRP 和 threepenny-gui,我什至不确定如何做基本的事情。

假设我有一个这样定义的函数

timesClicked :: Element -> Behavior Int
timesClicked elem = accumulate (+) 0 (1 <$ UI.click elem)

我想在页面上显示行为的值。

我可以做类似的事情

setup :: Window -> UI ()
setup rootWindow = void $ do
button <- UI.button #+ [ string "Clickity!" ]
output <- UI.p
getBody rootWindow #+
map element [ button, output ]

let clicks = timesClicked loginButton

编辑:工作完整代码 here .

我不知道如何将行为附加到输出中。

最佳答案

啊哈,我现在已经弄明白了,我把它留作其他人的例子。

timesClicked elem = accumB (0::Int) ( (+1) <$ UI.click elem)


setup :: Window -> UI ()
setup rootWindow = void $ do
button <- UI.button #+ [ string "Clickity!" ]
output <- UI.p
getBody rootWindow #+
map element [ button, output ]

clicks <- timesClicked button
-- sink :: ReadWriteAttr x i o -> Behavior i -> UI x -> UI x
element output # sink text (show <$> clicks)

如果有人想跟随我的进步,我已经把它放在github上了.

关于haskell - 来自行为的元素(功能响应式(Reactive)编程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20669327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com