[Haskell-cafe] Is this a correct explanation of FRP?

Heinrich Apfelmus apfelmus at quantentunnel.de
Fri Mar 30 14:33:51 CEST 2012

Michael Snoyman wrote:
> First you state that we shouldn't use `union` for the `ePitch` Event,
> and then you used it for `bOctave`. Would it be more efficient to
> implement bOctave as someting like:
>     eOctave :: Event t (Int -> Int)
>     eOctave =
>         filterJust toStep <$> eKey
>       where
>         toStep '+' = Just (+ 1)
>         toStep '-' = Just (subtract 1)
>         toStep _ = Nothing
>     bOctave :: Behavior t Octave
>     bOctave = accumB 0 eOctave

It's largely a matter of efficiency in notation rather than efficiency 
in run-time.

> Also, I'm left wondering: how would you create a new event stream in
> the first place? You're telling us to just rely on `eKey`, which is
> fair, but a great follow-up would demonstrate building it. Looking
> through the docs I found `newEvent`, but I'm not quite certain how I
> would combine it all together.

It's best to look at the example for that and peruse the documentation 
in  Reactive.Banana.Frameworks  in case something is unclear.

Best regards,
Heinrich Apfelmus


More information about the Haskell-Cafe mailing list