broccoli-0.1.0.0: Small library for interactive functional programs.

Safe HaskellNone
LanguageHaskell2010

X

Description

Small experimental library for interactive functional programs.

Synopsis

Documentation

data X a

A value of type a that varies.

Instances

data E a

An event that carries values of type a when it occurs.

Instances

Functor E 
Monoid (E a) 

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.

snapshot_ :: E a -> X b -> E b

Like snapshot but ignores the original event's payload.

filterE :: (a -> Bool) -> E a -> E a

Filter out events using a Bool function.

justE :: E (Maybe a) -> E a

Filter out events with the value of Nothing.

maybeE :: (a -> Maybe b) -> E a -> E b

Filter out events using a Maybe function.

never :: E a

An event that never happens.

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.

input :: IO () -> Setup ()

Spawn an input thread to generate source signals and events.

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.