
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.

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
participants (1)
-
Álvaro García Pérez