我第一次尝试使用 Reactive Banana (WX) 在五个按钮之上显示诸如“按下按钮一”、“按下按钮二”等文本:
{-# LANGUAGE ScopedTypeVariables #-}
import Graphics.UI.WX hiding (Event)
import Reactive.Banana
import Reactive.Banana.WX
data Buttons = One | Two | Three | Four | Five deriving (Show)
main :: IO ()
main = start $ do
f <- frame [text := “Five Buttons“]
bone <- button f [text := “One”]
btwo <- button f [text := “Two”]
bthree <- button f [text := “Three”]
bfour <- button f [text := “Four”]
bfive <- button f [text := “Five”]
out <- staticText f []
set f [layout := margin 10 $
column 5 [row 5 [widget bone, widget btwo, widget bthree, widget bfour, widget bfive],
grid 5 5 [[label “Output:” , widget out]
]]]
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
eone <- event0 bone command
etwo <- event0 btwo command
ethree <- event0 bthree command
efour <- event0 bfour command
efive <- event0 bfive command
let
somethinghere::Behaviour t Buttons
somethinghere = ....
sink out [text :== "Pressed button " ++ show <$> somethinghere]
network <- compile networkDescription
actuate network
代码只是主要骨架。我目前无法做的是填充somethinghere
方法。如前所述,如果例如按下按钮“One”,somethinghere
则应返回参考Buttons
ADT 数据One
等。我试过了accumB
,unionWith
但我认为我没有得到正确的机制。有什么帮助吗?