I finally understand how functional programming can work for real-time interactive graphical applications!

There's a new functional language called
Elm that compiles to HTML, CSS, and JavaScript for making websites and games.
The way it works is called
functional reactive programming, which basically means it recalculates the state of the virtual world whenever input values (keyboard, mouse, timers) change, and the graphical representation is calculated from the state of the virtual world so that updates too. All the code for the game basically describes the way this data flows and is transformed (through lots and lots of nested functions). As a result,
I think it could lend itself very naturally to a visual representation. It's basically just a big tree, a network of data flowing and combining, and if you see this structure you see the entire program.
This could be great for both
R-mode readability and
building with functional (no pun intended)
pieces in real time.
You can see a number of
simple examples, including a
detailed explanation of the code behind Pong.
Not exactly the prettiest code at first glance (probably more confusing than the kind of programming we're used to). I think the real potential here is in making it visual. We all know how Scratch looks, trying to make normal code visual. I think functional programming would actually look better in visual form than in text.
And in the long run, I bet functional programming would be much more amenable to
programming by demonstration - that is,
expressing general logic through specific examples.