Copyright  Copyright (c) 20092016 David Sorokin <david.sorokin@gmail.com> 

License  BSD3 
Maintainer  David Sorokin <david.sorokin@gmail.com> 
Stability  experimental 
Safe Haskell  None 
Language  Haskell2010 
Tested with: GHC 8.0.1
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 m a b = Circuit {
 runCircuit :: a > Event m (b, Circuit m a b)
 iterateCircuitInIntegTimes :: MonadDES m => Circuit m a a > a > Event m (Task m a)
 iterateCircuitInIntegTimes_ :: MonadDES m => Circuit m a a > a > Event m ()
 iterateCircuitInIntegTimesMaybe :: MonadDES m => Circuit m a (Maybe a) > a > Event m ()
 iterateCircuitInIntegTimesEither :: MonadDES m => Circuit m a (Either b a) > a > Event m (Task m (Either b a))
 iterateCircuitInTimes :: MonadDES m => [Double] > Circuit m a a > a > Event m (Task m a)
 iterateCircuitInTimes_ :: MonadDES m => [Double] > Circuit m a a > a > Event m ()
 iterateCircuitInTimesMaybe :: MonadDES m => [Double] > Circuit m a (Maybe a) > a > Event m ()
 iterateCircuitInTimesEither :: MonadDES m => [Double] > Circuit m a (Either b a) > a > Event m (Task m (Either b a))
 arrCircuit :: MonadDES m => (a > Event m b) > Circuit m a b
 accumCircuit :: MonadDES m => (acc > a > Event m (acc, b)) > acc > Circuit m a b
 arrivalCircuit :: MonadDES m => Circuit m a (Arrival a)
 delayCircuit :: MonadDES m => a > Circuit m a a
 timeCircuit :: MonadDES m => Circuit m a Double
 (<?<) :: MonadDES m => Circuit m b c > Circuit m a (Maybe b) > Circuit m a (Maybe c)
 (>?>) :: MonadDES m => Circuit m a (Maybe b) > Circuit m b c > Circuit m a (Maybe c)
 filterCircuit :: MonadDES m => (a > Bool) > Circuit m a b > Circuit m a (Maybe b)
 filterCircuitM :: MonadDES m => (a > Event m Bool) > Circuit m a b > Circuit m a (Maybe b)
 neverCircuit :: MonadDES m => Circuit m a (Maybe b)
 circuitSignaling :: MonadDES m => Circuit m a b > Signal m a > Signal m b
 circuitProcessor :: MonadDES m => Circuit m a b > Processor m a b
 integCircuit :: MonadDES m => Double > Circuit m Double Double
 integCircuitEither :: MonadDES m => Double > Circuit m (Either Double Double) Double
 sumCircuit :: (MonadDES m, Num a) => a > Circuit m a a
 sumCircuitEither :: (MonadDES m, Num a) => a > Circuit m (Either a a) a
 circuitTransform :: (MonadSD m, MonadDES m) => Circuit m a b > Transform m a b
 traceCircuit :: MonadDES m => Maybe String > Maybe String > Circuit m a b > Circuit m a b
The Circuit Arrow
newtype Circuit m a b Source #
Represents a circuit synchronized with the event queue. Besides, it allows creating the recursive links with help of the procnotation.
Circuit  

iterateCircuitInIntegTimes :: MonadDES m => Circuit m a a > a > Event m (Task m a) Source #
Iterate the circuit in the integration time points returning a task which completes after the final output of the circuit is received.
iterateCircuitInIntegTimes_ :: MonadDES m => Circuit m a a > a > Event m () Source #
Iterate the circuit in the integration time points.
iterateCircuitInIntegTimesEither :: MonadDES m => Circuit m a (Either b a) > a > Event m (Task m (Either b a)) Source #
Iterate the circuit in the integration time points returning a task
that computes the final output of the circuit either after all points
are exhausted, or after the Left
result of type b
is received,
which interrupts the computation immediately.
iterateCircuitInTimes :: MonadDES m => [Double] > Circuit m a a > a > Event m (Task m a) Source #
Iterate the circuit in the specified time points returning a task which completes after the final output of the circuit is received.
iterateCircuitInTimes_ :: MonadDES m => [Double] > Circuit m a a > a > Event m () Source #
Iterate the circuit in the specified time points.
iterateCircuitInTimesMaybe :: MonadDES m => [Double] > Circuit m a (Maybe a) > a > Event m () Source #
iterateCircuitInTimesEither :: MonadDES m => [Double] > Circuit m a (Either b a) > a > Event m (Task m (Either b a)) Source #
Iterate the circuit in the specified time points returning a task
that computes the final output of the circuit either after all points
are exhausted, or after the Left
result of type b
is received,
which interrupts the computation immediately.
Circuit Primitives
arrCircuit :: MonadDES m => (a > Event m b) > Circuit m a b Source #
Create a simple circuit by the specified handling function that runs the computation for each input value to get an output.
accumCircuit :: MonadDES m => (acc > a > Event m (acc, b)) > acc > Circuit m a b Source #
Accumulator that outputs a value determined by the supplied function.
The Arrival Circuit
arrivalCircuit :: MonadDES m => Circuit m a (Arrival a) Source #
A circuit that adds the information about the time points at which the values were received.
Delaying the Circuit
delayCircuit :: MonadDES m => a > Circuit m a a Source #
Delay the input by one step using the specified initial value.
The Time Circuit
timeCircuit :: MonadDES m => Circuit m a Double Source #
A circuit that returns the current modeling time.
Conditional Computation
:: MonadDES m  
=> Circuit m b c  process the event if it presents 
> Circuit m a (Maybe b)  whether there is an event 
> Circuit m a (Maybe c)  the resulting circuit that processes only the represented events 
Like <<<
but processes only the represented events.
:: MonadDES m  
=> Circuit m a (Maybe b)  whether there is an event 
> Circuit m b c  process the event if it presents 
> Circuit m a (Maybe c)  the resulting circuit that processes only the represented events 
Like >>>
but processes only the represented events.
filterCircuit :: MonadDES m => (a > Bool) > Circuit m a b > Circuit m a (Maybe b) Source #
Filter the circuit, calculating only those parts of the circuit that satisfy the specified predicate.
filterCircuitM :: MonadDES m => (a > Event m Bool) > Circuit m a b > Circuit m a (Maybe b) Source #
Filter the circuit within the Event
computation, calculating only those parts
of the circuit that satisfy the specified predicate.
Converting to Signals and Processors
circuitSignaling :: MonadDES m => Circuit m a b > Signal m a > Signal m b Source #
Get a signal transform by the specified circuit.
circuitProcessor :: MonadDES m => Circuit m a b > Processor m a b Source #
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).
:: MonadDES m  
=> Double  the initial value 
> Circuit m (Either Double Double) Double  map either a new 
Like integCircuit
but allows either setting a new Left
integral value,
or using the Right
derivative when integrating by Euler's method.
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).
:: (MonadDES m, Num a)  
=> a  the initial value 
> Circuit m (Either a a) a  map either a new 
Like sumCircuit
but allows either setting a new Left
value for the sum, or updating it
by specifying the Right
difference.
The Circuit Transform
circuitTransform :: (MonadSD m, MonadDES m) => Circuit m a b > Transform m a b Source #
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.