
Tried putting this on "Introducing Reactive: Events." But was having commenting issues. I wanted to make the BellMachines actually work with on the command line so I tried the following code.
runMachine :: BellMachine -> IO () runMachine machine = do -- get button press clock <- makeClock (buttonPressed, buttonPressedSink) <- makeEvent clock forkIO $ buttonPresses buttonPressedSink adaptE (fmap bell $ machine buttonPressed) -- run the machine where bell = const $ print "beep!" buttonPresses sink = sequence_ $ repeat $ (getChar >> sink ())
main = runMachine metronome
This guy works fine for the basic machines but it breaks for metronome. The first reason seems to be that when it gets to a point when there are no future events, switchE fails. "Exception: Future mempty: it'll never happen, buddy" I could hack around this, but then I got to another issue. It seems like switchE is too lazy, which causes my events always fire one click behind when I press the button. My guess is that since switchE is implemented with withRestE, it needs to peak ahead one event. Not sure how to deal with these issues in practice. Curious if I'm just doing something wrong. Thanks, Sasha

Hi Sasha,
Thanks for the report. Would you please add a ticket or two on
http://trac.haskell.org/reactive? (You'll have to register first.)
Anything you can do to simplify the breaking example would help.
And if you or anyone else wants to poke around toward nailing down the
underlying, that'd be great too.
Relevant QuickCheck tests are always appreciated as well.
- Conal
On Mon, Nov 10, 2008 at 6:53 PM, Sasha Rush
Tried putting this on "Introducing Reactive: Events." But was having commenting issues. I wanted to make the BellMachines actually work with on the command line so I tried the following code.
runMachine :: BellMachine -> IO () runMachine machine = do -- get button press clock <- makeClock (buttonPressed, buttonPressedSink) <- makeEvent clock forkIO $ buttonPresses buttonPressedSink adaptE (fmap bell $ machine buttonPressed) -- run the machine where bell = const $ print "beep!" buttonPresses sink = sequence_ $ repeat $ (getChar >> sink ())
main = runMachine metronome
This guy works fine for the basic machines but it breaks for metronome. The first reason seems to be that when it gets to a point when there are no future events, switchE fails.
"Exception: Future mempty: it'll never happen, buddy"
I could hack around this, but then I got to another issue. It seems like switchE is too lazy, which causes my events always fire one click behind when I press the button. My guess is that since switchE is implemented with withRestE, it needs to peak ahead one event.
Not sure how to deal with these issues in practice. Curious if I'm just doing something wrong.
Thanks, Sasha _______________________________________________ Reactive mailing list Reactive@haskell.org http://www.haskell.org/mailman/listinfo/reactive
participants (2)
-
Conal Elliott
-
Sasha Rush