从使用法线Int
保持计数器状态的 Reactive Banana Wx 中的 Counter 示例开始:
let networkDescription :: forall t. Frameworks t => Moment t ()
networkDescription = do
eup <- event0 bup command
edown <- event0 bdown command
let
counter :: Behavior t Int
counter = accumB 0 $ ((+1) <$ eup) `union` (subtract 1 <$ edown)
sink output [text :== show <$> counter]
network <- compile networkDescription
actuate network
如何Int
用更通用的方式替换和更新计数器data
:
data Counter = Counter {
count :: Int
} deriving (Show)
let
counter :: Behavior t Counter
counter = accumB Counter { count = 0 } $ ??????
sink output [text :== show <$> count counter]
我不知道如何用这样的count
东西来引用内部函数:
count = count mycounter + 1
任何想法?