- data PushIO
- run :: Typeable a => (Event PushIO a -> Event PushIO b) -> [a] -> IO [[b]]
- data Prepare a
- prepareEvents :: Prepare () -> IO ()
- reactimate :: Event PushIO (IO ()) -> Prepare ()
- type AddHandler a = (a -> IO ()) -> IO ()
- fromAddHandler :: Typeable a => AddHandler a -> Prepare (Event PushIO a)
- liftIO :: MonadIO m => forall a. IO a -> m a
- module Data.Dynamic
Run event networks and hook them up to existing event-based frameworks.
Running an event network for the purpose of easy testing.
Using existing event-based frameworks
After having read all about
you want to hook things up to an existing event-based framework,
How do you do that?
To do that, you have to use the
The typical setup looks like this:
main = do ... -- other initialization -- initialize event network prepareEvents $ do -- obtain Event from functions that register event handlers emouse <- fromAddHandler (registerMouseEvent window) ekeyboard <- fromAddHandler (registerKeyEvent window) -- build event network let behavior1 = accumB ... ... event15 = union event13 event14 -- animate relevant event occurences reactimate $ fmap print event15 reactimate $ fmap drawCircle eventCircle ... -- start the GUI framework here
In short, you use
fromAddHandler to obtain input events;
the library will register corresponding event handlers
with your event-based framework.
To animate output events, you use the
The whole setup has to be wrapped into a call to
Prepare monad is an instance of
IO is allowed inside. However, you can't pass anything
Behavior outside the
this is intentional.
(You can probably circumvent this with mutable variables,
but there is a 99,8% chance that earth will be suspended
by time-traveling zygohistomorphisms
if you do that; you have been warned.)
Animate an output event.
IO action whenever the event occurs.
A value of type
AddHandler a is just an IO function that registers
callback functions, also known as event handlers.
Event from an
This will register a callback function such that
an event will occur whenever the callback function is called.