Beliefs and the Unimpossibility of Functional Reactive Programming

Behaviors must be first class — this is a belief I have held for almost my entire tenure as an FRP researcher. The belief originated about two weeks after I learned of FRP, when I wrote my first FRP Arrow and in it tried to write a small game. The process was awkward; not as clean and natural as what I had dreamt of for the paradigm. The awkwardness arose when trying to wrangle a time-varying list of time-varying enemies. I concluded that Arrowized FRP (AFRP) was terrible at managing dynamic collections of behaviors, and therefore that an FRP system needed dynamic collections to be powerful enough to do nontrivial things.

Only half of my conclusion was justified. AFRP is indeed terrible at managing dynamic collections of behaviors. But I never questioned the latter half. It epitomizes what Conal Elliott calls “proof by lack of imagination”: since I couldn’t devise a way to write my game without dynamic collections, there must not be a way.

Conal and the rest of the FRP gang has been discussing the semantic junk in classic FRP. Clearly there is more (or rather, less) to an interactive Behavior than an arbitrary function between two non-interactive ones. This identified, my mind immediately jumped to Arrows. That is what they are for: function-like things that can’t do quite as much as regular functions.

And for some reason — perhaps it is my increased functional maturity — I feel no need for first-class behaviors anymore, no awkwardness for their lack. Programming with them doesn’t feel like the rest of functional programming. It feels too open-ended; i.e. I can say too much in the code without saying it in the type. I feel now like Arrows are a perfect fit for FRP. And fortunately, we already have an efficient AFRP implementation. It’s not a great implementation — there are semantic and operational details that could be improved, but it is something to start from, which is more than I had before.

I don’t blame myself for temporarily believing that we needed first-class behaviors. But I am disappointed in myself for taking so long to question that belief. FRP was my world. I was determined to understand it and to make it a practical alternative to Haskell’s IO. But I ended up blatantly ignoring half of the ongoing research because I didn’t believe it would work. This is not acceptable for a serious researcher.

The perfect way is only difficult for those who pick and choose.
Do not like, do not dislike; all will then be clear.
Make a hairbreadth difference, and Heaven and Earth are set apart.
If you want the truth to stand clearly before you, never be for or against.
The struggle between for and against is the mind’s worst disease.
— Zen master Sent-ts’an

About these ads

3 thoughts on “Beliefs and the Unimpossibility of Functional Reactive Programming

  1. Hi Luke. I like your post (as always). I’m glad you got unstuck, and I resonate with your ending quote very much. Here are some related quotes, from my collection of favorites, that you may like as well:

    “As long as you have certain desires about how it ought to be you can’t see how it is.” – Ram Dass

    “I have learned to use the word ‘impossible’ with the greatest caution.” – Wernher von Braun

    “A man demonstrates his rationality, not by a commitment to fixed ideas, stereotyped procedures, or immutable concepts, but by the manner in which, and the occasions on which, he changes those ideas, procedures, and concepts.” – Stephen Toulmin

    “When you become comfortable with uncertainty, infinite possibilities open up in your live. It means fear is no longer a dominant factor in what you do and no longer prevents you from taking action to initiate change. The Roman philosopher Tacitus rightly observed that ‘the desire for safety stands against every great and noble enterprise.’ If uncertainty is unacceptable to you, it turns into fear. If it is perfectly acceptable, it turns into aliveness, alertness and creativity.” – Eckhart Tolle, A New Earth

    “We too should make ourselves empty, that the great soul of the universe may fill us with its breath.” – Lawrence Binyon

  2. Hey Luke,
    My own opinion of “AFRP” has been swinging wildly. Most lately I’ve had a negative opinion for two reasons I’m pretty sure you agree with – they are more about the current implementation:
    1. The semantics are not clear. This is either only a documentation thing, or a deeper problem. I’m guessing its somewhere in between, because until we clarify the semantics precisely we can’t be sure that they’re completely ok.
    2. The code is messy, and it’s hard to tell the difference between primitives and utilities.

    And lastly, it’s not actively maintained (as far as I know). Despite all this, I have _still_ decided to use it for my FRP robot project (see link). Simply because I heard that Reactive has a few bugs (more than Yampa).

  3. Hi Luke,

    Well, I guess you know my opinion about Yampa :) For me – from an engineering point of view – it works well enough to write games in. Personally I never had a lot of problems with the dynamic switching in Yampa. I even don’t think dpSwitch is that bad, it is just an encapsulation of a typical game loop.

    But yes, Reactive is sooo much more beautiful, the seduction was hard to resist :) But in Dutch we have a saying: “Van een knappe tafel kun je niet eten”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s