grapefruit-frp- Functional Reactive Programming core

Safe HaskellNone



This module provides circuits which are descriptions of reactive systems.



data Circuit era i o Source

A circuit describes a reactive system.

The era parameter denotes the time interval during which the circuit is in existence. It is completely analogous to the era parameters of signal types which are described in the documentation of FRP.Grapefruit.Signal.

Input and output of a circuit are typically signals, tuples of signals (with () as the corner case) or records of signals as provided by the package grapefruit-records. The era parameters of these signals usually match the era parameter of the circuit.

A circuit consumes only one input value and produces only one output value. This happens when the circuit is constructed. So the temporal behavior does not come from turning multiple inputs into multiple outputs but from using signals as inputs and outputs.

A circuit has the ability to interact with the outside world (that is, perform I/O).

The ArrowApply instance of Circuit era is currently needed for implementing other parts of Grapefruit. However, it should not be taken for granted that it will remain in future versions. So it is better to not use it outside Grapefruit.


act :: Circuit era (IO output) outputSource

This circuit takes an I/O action when it is constructed, performs this action immediately and outputs its result.

putSetup :: Circuit era Setup ()Source

A circuit which triggers initialization and finalization according to a given setup.

create :: (forall era. Circuit era i o) -> i -> IO (o, IO ())Source

Creates a circuit.

The second argument of create is fed into the circuit as its input and the circuit is constructed then. After that, the initialization actions of all setups inserted by putSetup are run. The finalization actions of the setups are chained and returned by create together with the output of the circuit.

Note that initialization is done completely after circuit creation. This allows outputs of circuits to be generated before they are used for forming circuit inputs. This is important to avoid circular dependencies when loop is used.