- 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
Synopsis
Run event networks and hook them up to existing event-based frameworks.
Implementation
run :: Typeable a => (Event PushIO a -> Event PushIO b) -> [a] -> IO [[b]]Source
Running an event network for the purpose of easy testing.
Using existing event-based frameworks
After having read all about Event
s and Behavior
s,
you want to hook things up to an existing event-based framework,
like wxHaskell
or Gtk2Hs
.
How do you do that?
To do that, you have to use the Prepare
monad.
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 reactimate
function.
The whole setup has to be wrapped into a call to prepareEvents
.
The Prepare
monad is an instance of MonadIO
,
so IO
is allowed inside. However, you can't pass anything
of type Event
or Behavior
outside the prepareEvents
call;
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.)
reactimate :: Event PushIO (IO ()) -> Prepare ()Source
Animate an output event.
Executes the IO
action whenever the event occurs.
type AddHandler a = (a -> IO ()) -> IO ()Source
A value of type AddHandler a
is just an IO function that registers
callback functions, also known as event handlers.
fromAddHandler :: Typeable a => AddHandler a -> Prepare (Event PushIO a)Source
Obtain an Event
from an AddHandler
.
This will register a callback function such that
an event will occur whenever the callback function is called.
module Data.Dynamic