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

Michael Snoyman michael at snoyman.com
Fri Mar 30 08:15:11 CEST 2012


On Thu, Mar 29, 2012 at 7:15 PM, Peter Minten <peter.minten at orange.nl> wrote:
> Hi,
>
> I've been trying to get my head around Functional Reactive Programming
> by writing a basic explanation of it, following the logic that
> explaining something is the best way to understand it.
>
> Am I on the right track with this explanation?

Hi Peter,

I'm no expert on FRP (in fact, I'm just trying to understand it), so I
can't speak to the technical accuracy of your post. However, I think
you're absolutely on the right track as far as explaining what FRP is.
I think you've done a great job of explaining things from the ground
up. Thank you! I just had a few questions.

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

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.

Thanks again for writing this up.

Michael



More information about the Haskell-Cafe mailing list