[reactive] Fwd: First steps in FRP
Álvaro García Pérez
agarcia at babel.ls.fi.upm.es
Mon Jun 8 08:31:05 EDT 2009
Hi,
I've found Sasha's example
> import FRP.Reactive
> import FRP.Reactive.LegacyAdapters
> import Control.Concurrent
> type BellMachine = Event () -> Event ()
> doorBell :: BellMachine
> doorBell = id
> 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 doorBell
and it fits my purposes, but notice that the values collected from the
makeEvent function must be in reverse order, at least with reactive-0.11.
> (buttonPressedSink, buttonPressed) <- makeEvent clock
Regards,
Alvaro.
---------- Mensaje reenviado ----------
De: Álvaro García Pérez <agarcia at babel.ls.fi.upm.es>
Fecha: 8 de junio de 2009 11:57
Asunto: First steps in FRP
Para: reactive at haskell.org
Hello,
I'm new to FRP and I'm trying to write a simple program adapting the events
to IO. I've read the tutorial "Introducing Reactive: Events" but it's not
very clear how to do it. Can someone send me an example? I would like to
capture events from IO (let's say, keyboard strokes) and print text in the
console. I'm using the last version of the reactive package.
Thanks,
Alvaro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20090608/c614cc28/attachment.html
More information about the Reactive
mailing list