Etage-0.1.8: A general data-flow framework

Control.Etage.Delay

Description

This module defines a Neuron which delays received Impulses before sending them further. In this way network can have a simple kind of memory (state) without a need of special Neurons. You grow it in Incubation by using something like:

 nerveDelay <- (growNeuron :: NerveBoth (DelayNeuron IInteger)) (\o -> o { delay = 2 })

Sometimes the same effect can be achieved by using a Nerve as a queue and using fuseWith (or fuse) to synchronize (and thus delay) Impulses. For example, the following two programs both output Fibonacci sequence:

 incubate $ do
   nerveDump <- (growNeuron :: NerveOnlyFor DumpNeuron) (\o -> o { showInsteadOfDump = True })
   nerveDelay <- (growNeuron :: NerveBoth (DelayNeuron IInteger)) defaultOptions
   nerveSum <- (growNeuron :: NerveBoth (FunctionNeuron IIntegerList IInteger)) (\o -> o { function = \t -> (: []) . IValue t . sum . list })
   nerveFused <- [TranslatableFrom nerveDelay, TranslatableFrom nerveSum] `fuseWith` (listFuser :: ImpulseTime -> [IInteger] -> [IIntegerList])
   
   nerveSum `attachTo` [TranslatableFor nerveDelay, TranslatableFor nerveDump]
   nerveFused `attachTo` [TranslatableFor nerveSum]
   
   liftIO $ do
     t <- getCurrentImpulseTime
     sendFromNeuron nerveSum $ IValue t 1
     sendFromNeuron nerveDelay $ IValue t 0
 incubate $ do
   nerveDump <- (growNeuron :: NerveOnlyFor DumpNeuron) (\o -> o { showInsteadOfDump = True })
   nerveSum <- (growNeuron :: NerveBoth (FunctionNeuron IIntegerList IInteger)) (\o -> o { function = \t -> (: []) . IValue t . sum . list })
   
   liftIO $ do
     t <- getCurrentImpulseTime
     sendFromNeuron nerveSum $ IValue t 0
   
   nerveSum' <- liftIO $ branchNerveFrom nerveSum
   nerveFused <- [TranslatableFrom nerveSum, TranslatableFrom nerveSum'] `fuseWith` (listFuser :: ImpulseTime -> [IInteger] -> [IIntegerList])
   
   nerveSum `attachTo` [TranslatableFor nerveDump]
   nerveFused `attachTo` [TranslatableFor nerveSum]
   
   liftIO $ do
     t <- getCurrentImpulseTime
     sendFromNeuron nerveSum $ IValue t 1

This Neuron processes all Impulses it receives.

Synopsis

Documentation

data DelayNeuron i Source

Instances

type DelayOptions i = NeuronOptions (DelayNeuron i)Source

Options for DelayNeuron. This option is defined:

delay :: Int
For how many Impulses should received Impulses be delayed before sending them. Default value is 1.