Updater-0.3: Monadic FRP library based on stm

Safe HaskellNone
LanguageHaskell98

Updater

Synopsis

Documentation

data Event a Source

Push based Updater.

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

cacheStateful :: Event a -> Behavior (Event a) Source

The input will only be evaluated once, no matter how often the ouput Event is used. Since it is stateful, when the output Event is used, it will immediately continue with the last Event it received if such an event exists.

cacheStateless :: Event a -> Behavior (Event a) Source

The input will only be evaluated once, no matter how often the output Event is used. Since it is stateless, when the output Event is used, it will first have to wait for events.

sample :: Behavior a -> Event a Source

This can be thought of as polling a behavior. It will only fire once.

foldEvent :: (b -> a -> b) -> b -> Event a -> Event b Source

This can be implemented using mfix, cacheStateful, ...

If you get into trouble and really need multiple recursively defined Events you can use mfix to do that. You should however look at the implementation of foldEvent and the SlotMachine example first. In particular, make sure you understande that you need to use 'sample . hold' on the recursive signal in order to avoid infinite recursion.

runEvent :: Event (Either (IO ()) res) -> IO res Source

'Left io' events will be executed. The first 'Right res' event will end the function and return res.

runGlobalEvent :: Event (IO ()) -> IO () Source

This is just a convenience for use in ghci and in the test cases. It will just run the Event it is given in it's own thread.

debug :: String -> Behavior () Source

Just for some quick debugging

putLine = unsafeLiftIO . putStrLn

debugCleanup :: String -> Behavior () Source

This can be useful to spot when listeners are removed.

hold :: Event a -> Behavior a Source

This just only forwards the first event It is probably most useful for Events crated using cacheStateful

unsafeLiftIO :: IO a -> Behavior a Source

Don't execute the io-action returned by newEvent. Also, fork; don't block.