reaction-logic-2010.11.17: pluggable pure logic serializable reactor



Reaction box and stepping function. Reactions leave the monad parameter free for the programmer. Around m a state transformer gives them the chance to use per reaction state.



data Reaction m Source

A Reaction object is a container for a reaction. It's free in the type of value to react and in its internal state.


forall a b . (Typeable a, Show b, Read b, Typeable b) => Reaction 


reaction :: a -> StateT b m (Response m)

The reaction to an event of type a. It can modify its individual state in the outer monad layer. There are no constraint on the inner monad.

reastate :: b

Internal state of the reaction. Upon creation it must contatin the initial state.



:: (Monad m, Functor m) 
=> Reaction m

reaction box containing the reaction to try

-> Internal

the event for the reaction

-> Maybe (m ([Reaction m], [Internal], Maybe (Reaction m)))

new reactions, events and possibly a renewed Reaction, or Nothing if the reaction is dead

Try a reaction of a Reaction, given an event in an Untyped box. If the event is not of the right type, the result is Nothing, otherwise an action in the monad m returning a modified Response, with Bool mapped to Maybe (Reaction m).

type External = SerialSource

External event, it must be serializable

type Internal = UntypedSource

Internal event, don't need to be serializable

type Recover = SerialSource

Internal state serializations, it must be serializable

data Response m Source

The value reactions compute.




continue :: Bool

True to continue the reaction, or False if reaction if dead

newreas :: [Reaction m]

a list of new reactions, just borned ready for the next event

newevents :: [Internal]

some events to broadcast now as effects of the reaction