[reactive] Re: Whoever implements splitB gets a virtual beer from me.

David Sankel camior at gmail.com
Mon Nov 24 16:01:15 EST 2008


Replying to my own request:

http://netsuperbrain.com/blog/posts/why-is-the-reactive-behavior-tutorial-taking-so-long-splitb/

-- 
David Sankel

On Thu, Nov 13, 2008 at 1:53 PM, David Sankel <camior at gmail.com> wrote:
> 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
>


More information about the Reactive mailing list