I would like to do something like this:
handlerOn = do
cid <- canvas `on` buttonPressEvent $ tryEvent do
signalDisconnect cid
handlerOff
putStrLn "handlerOn"
handlerOff = do
cid <- canvas `on` buttonPressEvent $ tryEvent do
signalDisconnect cid
handlerOn
putStrLn "handlerOff"
This won't work as it is, of course, because I'm trying to use cid inside a code block where cid is not assigned yet.
The idea is to register an event listener that when it receives an event, it will deregister itself and register a different event listener which will do the same, back and forth.
GHC supports recursive
do
.You could also use
Control.Monad.Fix
.Or manage the handler yourself.
Or just make everything into a single handler.