Stability  experimental 

Maintainer  David Sorokin <david.sorokin@gmail.com> 
Safe Haskell  SafeInferred 
Tested with: GHC 7.6.3
It represents a circuit synchronized with the event queue. Also it allows creating the recursive links with help of the procnotation.
The implementation is based on the Arrow Tutorial.
 newtype Circuit a b = Circuit {
 runCircuit :: a > Event (Circuit a b, b)
 arrCircuit :: (a > Event b) > Circuit a b
 accumCircuit :: (acc > a > Event (acc, b)) > acc > Circuit a b
 arrivalCircuit :: Circuit a (Arrival a)
 delayCircuit :: a > Circuit a a
 timeCircuit :: Circuit a Double
 (<?<) :: Circuit b c > Circuit a (Maybe b) > Circuit a (Maybe c)
 (>?>) :: Circuit a (Maybe b) > Circuit b c > Circuit a (Maybe c)
 filterCircuit :: (a > Bool) > Circuit a b > Circuit a (Maybe b)
 filterCircuitM :: (a > Event Bool) > Circuit a b > Circuit a (Maybe b)
 neverCircuit :: Circuit a (Maybe b)
 circuitSignaling :: Circuit a b > Signal a > Signal b
 circuitProcessor :: Circuit a b > Processor a b
 integCircuit :: Double > Circuit Double Double
 sumCircuit :: Num a => a > Circuit a a
 circuitTransform :: Circuit a b > Transform a b
Circuit Arrow
Represents a circuit synchronized with the event queue. Besides, it allows creating the recursive links with help of the procnotation.
Circuit  

Circuit Primitives
arrCircuit :: (a > Event b) > Circuit a bSource
Lift the Event
function to a curcuit.
accumCircuit :: (acc > a > Event (acc, b)) > acc > Circuit a bSource
Accumulator that outputs a value determined by the supplied function.
Arrival Circuit
arrivalCircuit :: Circuit a (Arrival a)Source
A circuit that adds the information about the time points at which the values were received.
Delaying Circuit
delayCircuit :: a > Circuit a aSource
Delay the input by one step using the specified initial value.
Time Circuit
timeCircuit :: Circuit a DoubleSource
A circuit that returns the current modeling time.
Conditional Computation
:: Circuit b c  process the event if it presents 
> Circuit a (Maybe b)  whether there is an event 
> Circuit a (Maybe c)  the resulting circuit that processes only the represented events 
Like <<<
but processes only the represented events.
:: Circuit a (Maybe b)  whether there is an event 
> Circuit b c  process the event if it presents 
> Circuit a (Maybe c)  the resulting circuit that processes only the represented events 
Like >>>
but processes only the represented events.
filterCircuit :: (a > Bool) > Circuit a b > Circuit a (Maybe b)Source
Filter the circuit, calculating only those parts of the circuit that satisfy the specified predicate.
filterCircuitM :: (a > Event Bool) > Circuit a b > Circuit a (Maybe b)Source
Filter the circuit within the Event
computation, calculating only those parts
of the circuit that satisfy the specified predicate.
neverCircuit :: Circuit a (Maybe b)Source
The source of events that never occur.
Converting to Signals and Processors
circuitSignaling :: Circuit a b > Signal a > Signal bSource
Get a signal transform by the specified circuit.
circuitProcessor :: Circuit a b > Processor a bSource
Transform the circuit to a processor.
Integrals and Difference Equations
An approximation of the integral using Euler's method.
This function can be rather inaccurate as it depends on
the time points at wich the Circuit
computation is actuated.
Also Euler's method per se is not most accurate, although simple
enough for implementation.
Consider using the integ
function whenever possible.
That function can integrate with help of the RungeKutta method by
the specified integration time points that are passed in the simulation
specs to every Simulation
, when running the model.
At the same time, the integCircuit
function has no mutable state
unlike the former. The latter consumes less memory but at the cost
of inaccuracy and relatively more slow simulation, had we requested
the integral in the same time points.
Regarding the recursive equations, the both functions allow defining them but whithin different computations (either with help of the recursive donotation or the procnotation).
A sum of differences starting from the specified initial value.
Consider using the more accurate diffsum
function whener possible as
it is calculated in every integration time point specified by specs
passed in to every Simulation
, when running the model.
At the same time, the sumCircuit
function has no mutable state and
it consumes less memory than the former.
Regarding the recursive equations, the both functions allow defining them but whithin different computations (either with help of the recursive donotation or the procnotation).
Circuit Transform
circuitTransform :: Circuit a b > Transform a bSource
Approximate the circuit as a transform of time varying function, calculating the values in the integration time points and then interpolating in all other time points. The resulting transform computation is synchronized with the event queue.
This procedure consumes memory as the underlying memoization allocates an array to store the calculated values.