broccoli-0.2.0.0: Small library for interactive functional programs.

Safe HaskellNone
LanguageHaskell2010

Control.Broccoli

Description

Small experimental library for interactive functional programs.

Synopsis

Documentation

data X a Source

A value of type a that varies.

Instances

data E a Source

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

Instances

Functor E 
Monoid (E a) 

never :: E a Source

An event that never happens.

snapshot :: E a -> X b -> E (a, b) Source

An event which gets the value of a signal when another event occurs.

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

Like snapshot but ignores the original event's payload.

accumulate :: E a -> s -> (a -> s -> s) -> X s Source

Sum over events using an initial state and a state transition function.

edge :: X a -> (a -> a -> Maybe b) -> E b Source

An event that occurs when an edge is detected in a signal. The edge test is applied to values before and after a discrete transition in the signal. The test should return Nothing when the two values are the same.

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

Filter out events with the value of Nothing.

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

Filter out events using a Maybe function.

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

Filter out events using a Bool function.

data Setup a Source

A monad for hooking up inputs and outputs to a program.

runProgram :: Setup (IO (), E ()) -> IO () Source

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.

newX :: a -> Setup (X a, a -> IO ()) Source

Creates a new signal and an IO action to update it. The argument is the initial value of the signal.

newE :: Setup (E a, a -> IO ()) Source

Creates a new event and an IO action to trigger it.

input :: IO () -> Setup () Source

Spawn an input thread to generate source signals and events.

output :: E a -> (a -> IO ()) -> Setup () Source

Spawn a thread to execute an action for each event occurrence.

debugX :: (Eq a, Show a) => X a -> X a Source

Print out transitions in a signal. Only for debugging purposes.

debugE :: Show a => E a -> E a Source

Print out events as they occur. Only for debugging purposes.