[reactive] Whoever implements splitB gets a virtual beer from me.
David Sankel
camior at gmail.com
Thu Nov 13 13:53:03 EST 2008
I'd like to design a function that splits behaviors based on the time of an
event occurrence. Here is the type signature:
splitB_ :: Behavior a -> Behavior a -> Event () -> Event (Behavior a)
An example in semantics:
splitB_ (const 1) (const 2) [(0,()), (1,())] => [ (0, (\t -> if t <= 0 then
1 else 2))
, (1, (\t -> if t <= 1 then
1 else 2))
]
Operationally, the implementation must avoid traversing all of the second
behavior's reactive's steps at every occurrence of the event, so the
following implementation isn't going to win anyone a beer:
splitB_ :: Behavior a -> Behavior a -> Event () -> Event (Behavior a)
splitB_ bLeft bRight e = fmap f (withTimeE_ e)
where
f ot = iffB (fmap (ot >=) time) bLeft bRight
iffB :: Behavior Bool -> Behavior a -> Behavior a -> Behavior a
iffB = liftA3 iff
iff a b c = if a then b else c
Thanks!
David
--
David Sankel
Sankel Software
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20081113/8cc568b9/attachment.htm
More information about the Reactive
mailing list