Etage-0.1.8: A general data-flow framework

Control.Etage.Function

Description

This module defines a Neuron which applies a given function to received Impulses. As Haskell is a lazy language this does not mean that the result will be immediately (fully) evaluated but that it will be evaluated when (and if) the result will be needed (probably in some other Neuron). You grow it in Incubation by using something like:

 nerveFunction <- (growNeuron :: NerveBoth (FunctionNeuron AnyImpulse IRational)) (\o -> o { function = \t -> (: []) . IValue t . sum . impulseValue })

This example can receive any Impulse type (AnyImpulse) and returns sum of its data payload (as given by impulseValue) as IRational type.

The following example calculates the greatest common divisor (gcd):

 incubate $ do
   let gcd t IList { list = (a:b:is) } = let r = a `mod` b in if r == 0 then [IList t (b:is)] else [IList t (b:r:is)]
       gcd _ _ = []
   
   nerveDump <- (growNeuron :: NerveOnlyFor DumpNeuron) (\o -> o { showInsteadOfDump = True })
   nerveSum <- (growNeuron :: NerveBoth (FunctionNeuron IIntegerList IIntegerList)) (\o -> o { function = gcd })
   
   nerveSum `attachTo` [TranslatableFor nerveSum, TranslatableFor nerveDump]
   
   liftIO $ do
     t <- getCurrentImpulseTime
     sendForNeuron nerveSum $ IList t [110, 80, 5]

This Neuron is an example of a Neuron with both receiving and sending Impulses types parametrized. It processes only the newest Impulses it receives, when they get queued, so Impulses are dropped if load is too high.

Synopsis

Documentation

data FunctionNeuron i j Source

Instances

Typeable2 FunctionNeuron 
(Impulse i, Impulse j) => Show (FunctionNeuron i j) 
(Impulse i, Impulse j) => Neuron (FunctionNeuron i j)

A Neuron which applies a given function to received Impulses.

type FunctionOptions i j = NeuronOptions (FunctionNeuron i j)Source

Options for FunctionNeuron. This option is defined:

function :: ImpulseTime -> i -> [j]
The function to apply to recieved Impulses. Resulting Impulses are send in the list order. Default is to always return an empty list.