I read the state of the button (whether pressed or not) every moment:
readButton :: IO Boolean
readButton = ...
main = do
(add, fire) <- newAddHandler
network <- compile (desc add)
actuate network
forever $ do
buttonState <- readButton
fire buttonState
desc addButtonEvent = do
eButtonState <- fromAddHandler addButtonEvent
...
All read states are stored in the eButtonStatenetwork description desc.
The button is considered to be pressed again when the current state of the moment 1, with the previous moment 0. So, if the sequence of events was a list, the function would be written like this:
f :: [Bool] -> Bool
f (True:False:_) = True
f _ = False
I want to apply this function to eButtonStateto find out if a button is currently pressed or not.
Is it possible? How would you do that? I would appreciate if there is a better or more general idea or method to achieve this.
source
share