threepenny-gui-0.1.0.1: Small GUI framework that uses the web browser as a display.

Safe HaskellSafe-Inferred

Control.Event

Contents

Synopsis

Synopsis

Event-driven programming in the imperative style.

Documentation

type Handler a = a -> IO ()Source

An event handler is a function that takes an event value and performs some computation.

newtype Event a Source

An event is a facility for registering event handlers. These will be called whenever the event occurs.

When registering an event handler, you will also be given an action that unregisters this handler again.

 do unregisterMyHandler <- register event myHandler

Constructors

Event 

Fields

register :: Handler a -> IO (IO ())
 

Instances

mapIO :: (a -> IO b) -> Event a -> Event bSource

Map the event value with an IO action.

filterIO :: (a -> IO Bool) -> Event a -> Event aSource

Filter event values that don't return True.

filterJust :: Event (Maybe a) -> Event aSource

Keep only those event values that are of the form Just.

newEvent :: IO (Event a, a -> IO ())Source

Build a facility to register and unregister event handlers. Also yields a function that takes an event handler and runs all the registered handlers.

Example:

 do
     (event, fire) <- newEvent
     register event (putStrLn)
     fire "Hello!"

newEventsTagged :: Ord tag => IO (tag -> Event a, (tag, a) -> IO ())Source

Build several Events from case analysis on a tag. Generalization of newEvent.