moduleInternal.Circuit(Circuit(Circuit),CircuitArrow,getECFinalizerAdd,getECFinalization,getStartTimeID)where-- ControlimportControl.CategoryasCategoryimportControl.ArrowasArrowimportControl.Arrow.OperationsasArrowOperationsimportControl.Arrow.TransformerasArrowTransformerimportControl.Arrow.Transformer.ReaderasReaderArrowimportControl.Arrow.Transformer.WriterasWriterArrowimportControl.Concurrent.MVarasMVar-- DataimportData.UniqueasUnique-- FRP.GrapefruitimportFRP.Grapefruit.SetupasSetup{-|
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.
-}newtypeCircuiteraio=Circuit(CircuitArrowio)deriving(Category,Arrow,ArrowLoop,ArrowApply)typeCircuitArrow=ReaderArrowUniqueECFinVarReaderArrowtypeECFinVarReaderArrow=ReaderArrow(MVar(IO()))SetupWriterArrowtypeSetupWriterArrow=WriterArrowSetupIOArrowtypeIOArrow=KleisliIO-- “EC” stands for “event cycle”getECFinalizerAdd::Circuitera()(IO()->IO())getECFinalizerAdd=Circuit$lift$readState>>>arraddFinalizerwhereaddFinalizerfinalizerVarfinalizer=modifyMVar_finalizerVar((>>finalizer)>>>return)getECFinalization::Circuitera()(IO())getECFinalization=Circuit$lift$readState>>>arr(\finalizerVar->dofinalizer<-takeMVarfinalizerVarputMVarfinalizerVar(return())finalizer)getStartTimeID::Circuitera()UniquegetStartTimeID=Circuit$readState