[Haskell-cafe] coding a queue with reactive
ryani.spam at gmail.com
Mon Feb 14 10:56:15 CET 2011
One way to think about Reactive's notion of "Future" is as a single
element of an event stream--something that might happen (yielding a
value) some time in the future.
'mempty' on futures is a future that never happens, and 'mappend' says
to pick the first of two futures to happen.
m >>= k waits for m's future to happen, then passes the result onto k.
So my definition of stateMachine says:
- Wait for either the future returned by 'run s0' or the first event
in the input event stream.
- If the future returned by 'run s0' happens first, we have an event
instance--return an event whose 'rest of the event stream' is the next
state of the state machine
- If the future from the input event stream happens first, update the
state and continue without spawning an event.
- If they happen at the same time, 'run s0' wins (mappend is left-biased)
More information about the Haskell-Cafe