Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Signal a
- newSignal :: Updater (a -> Updater (), Signal a)
- getValue :: Signal a -> Updater (Maybe a)
- data Updater a
- runUpdater :: Updater a -> IO a
- getEvent :: Signal a -> Updater a
- onCommit :: IO () -> Updater ()
- onCleanup :: Updater () -> Updater ()
- stop :: Updater a
- getBehavior :: Signal a -> Updater a
- local :: Updater a -> Updater ()
- liftSTM :: STM a -> Updater a
- putLine :: String -> Updater ()
Signals
Signal
is the portable Signal they can be exchanged between
any parts of your program. Internally, they are just a variable and a list of
change hooks.
newSignal :: Updater (a -> Updater (), Signal a) Source
Creates a new signal and gives you a way to update it. It is important to note that because the signal and the update function are separate, you can easily have readonly, writeonly permissions.
getValue :: Signal a -> Updater (Maybe a) Source
Gets the current value. Return Nothing if the signal is uninitialized.
Updater Monad
This monad works very similar to a continuation monad on top of stm.
You can do any basic stm computation you want simply using liftSTM
.
However, if you use getEvent
everything after that call will be executed
everytime the Signal
given to getEvent
is changed.
You can also use the Alternative
instance to make a union of events.
You can also use the Applicative
instance to run two things 'parallel'.
Parallel meaning that events on one side will not cause the other
side to be reevaluated completely.
runUpdater :: Updater a -> IO a Source
getEvent :: Signal a -> Updater a Source
Runs everything below it everytime its input signal is updated.
onCommit :: IO () -> Updater () Source
IO actions given here will be executed once a signal update has been completed. They keep the order in which they are inserted.
Helpers
Just a synonym for empty
from Alternative
.
It basically prevents signals from ever progressing beyond this point.
You can use this to make a filter for instance
when (condition) stop
getBehavior :: Signal a -> Updater a Source
Similar to getEvent
except that it also fires an event immediately,
if the input signal is already initialized. It can be created using getEvent
and
Alternative