[reactive] Laziness and IO adapters

Conal Elliott conal at conal.net
Mon Nov 10 22:43:03 EST 2008


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 <sasha.rush at gmail.com> wrote:

> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/reactive
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20081110/322cf230/attachment-0001.htm


More information about the Reactive mailing list