| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
X
Description
Small experimental library for interactive functional programs.
- data X a
- data E a
- data Setup a
- edge :: X a -> (a -> a -> Maybe b) -> E b
- accumulate :: E a -> s -> (a -> s -> s) -> X s
- snapshot :: E a -> X b -> E (a, b)
- snapshot_ :: E a -> X b -> E b
- filterE :: (a -> Bool) -> E a -> E a
- justE :: E (Maybe a) -> E a
- maybeE :: (a -> Maybe b) -> E a -> E b
- never :: E a
- newX :: a -> Setup (X a, a -> IO ())
- newE :: Setup (E a, a -> IO ())
- input :: IO () -> Setup ()
- output :: E a -> (a -> IO ()) -> Setup ()
- runProgram :: Setup (IO (), E ()) -> IO ()
Documentation
edge :: X a -> (a -> a -> Maybe b) -> E b
Events will occur when an "edge" is detected in a signal. The detection algorithm checks the two values before and after a discrete change in the signal.
The edge test must return Nothing when the two arguments are the same.
accumulate :: E a -> s -> (a -> s -> s) -> X s
Create a signal out of an input event and a state machine.
snapshot :: E a -> X b -> E (a, b)
An event which gets the value of a signal when another event occurs.
newX :: a -> Setup (X a, a -> IO ())
Create a new signal with an initial value. Get back an IO action to change the value of the signal. This is the only way the signal will change.
newE :: Setup (E a, a -> IO ())
Create a new event and the associated IO action to trigger the event.
output :: E a -> (a -> IO ()) -> Setup ()
Spawn a thread to execute an action for each event occurrence.
runProgram :: Setup (IO (), E ()) -> IO ()
Run the setup action to create input and output threads. The returned IO action will be executed when setup is complete. runProgram blocks until the returned event occurs, at which time it kills all the threads and returns.