Safe Haskell | None |
---|
Control.Etage.Function
Description
This module defines a Neuron
which applies a given function to received Impulse
s. 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 Impulse
s types parametrized. It processes only the newest Impulse
s it receives, when
they get queued, so Impulse
s are dropped if load is too high.
- data FunctionNeuron i j
- type FunctionFromImpulse i j = NeuronFromImpulse (FunctionNeuron i j)
- type FunctionForImpulse i j = NeuronForImpulse (FunctionNeuron i j)
- type FunctionOptions i j = NeuronOptions (FunctionNeuron i j)
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 |
type FunctionFromImpulse i j = NeuronFromImpulse (FunctionNeuron i j)Source
Impulse
s from FunctionNeuron
, of type j
.
type FunctionForImpulse i j = NeuronForImpulse (FunctionNeuron i j)Source
Impulse
s for FunctionNeuron
, of type i
.
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
Impulse
s. ResultingImpulse
s are send in the list order. Default is to always return an empty list.