Dana

Luke Palmer and Nick Szabo can shoot me for this if they want, but I think this is warranted, and I want to connect a couple of dots as well. Luke is one of a number of computer scientists, with Conal Elliott probably being the best known, who have devoted quite a bit of attention to Functional Reactive Programming, or FRP. FRP has been discussed on LtU off and on over the years, but, unusually for LtU IMHO, does not seem to have gotten the traction that some other similarly abstruse subjects have.

In parallel, LtU has had a couple of interesting threads about Second Life's economy, smart contracts, usage control, denial of service, technical vs. legal remedies, and the like. I would particularly like to call attention to this post by Nick Szabo, in which he discusses a contract language that he designed:

Designing the contract language radically changed my idea of what program flow and instruction pointers can be. Its successor, a general-purpose programming language, may thereby make event-oriented programming and concurrency far easier. The language is targeted at GUI programming as well as smart contracts, real-time, and workflow programming. My answer to the problems of concurrency and event handling is to make the ordering of instructions the syntactic and semantic core of the language. The order of execution and event handlers are the easiest things to express in the language rather than kludged add-ons to a procedural or functional language.

In recent private correspondence, Nick commented that he'd determined that he was reinventing synchronous programming à la Esterel, and mentioned "Reactive" programming.

Ding!

To make a potentially long entry somewhat shorter, Luke is working on a new language, Dana, which appears to have grown out of some frustration with existing FRP systems, including Conal Elliot's Reactive, currently perhaps the lynchpin of FRP research. Luke's motivating kickoff post for the Dana project can be found here, and there are several follow-up posts, including links to experimental source code repositories. Of particularly motivating interest, IMHO, is this post, where Luke discusses FRP's interaction with garbage collection succinctly but nevertheless in some depth. Luke's most recent post makes the connection from Dana, which Luke has determined needs to have a dependently-typed core, to Illative Combinatory Logic, explicit, and offers a ~100 line type checker for the core.

I find this very exciting, as I believe strongly in the project of being able to express computation centered on time, in the sense of Nick's contract language, in easy and safe ways extremely compelling. I've intuited for some time now that FRP represents a real breakthrough in moving us past the Von Neumann runtime paradigm in fundamental ways, and between Conal Elliott's and Luke's work (and no doubt that of others), it seems to me that my sense of this may be borne out, with Nick's contract language, or something like it, as an initial application realm.

So I wanted to call attention to Luke's work, and by extension recapitulate Conal's and Nick's, both for the PLT aspects that Luke's clearly represents, but also as a challenge to the community to assist in the realization of Nick's design efforts, if at all possible.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Ack, all of the Dana stuff

Ack, all of the Dana stuff is hosted on Wordpress so I can't access any of the blog posts behind the great firewall of China. It seems like we've been there/done that. There seem to be various approaches ranging from formal to less formal, its unclear if the less formal systems (e.g., SuperGlue) can be considered FRP.

Actually, I wasn't aware of Reactive previously. I have a hard time understanding formal FRP because it often seems to just be fighting against the purity straight jacket that Haskell puts you in. And how does purity make programmers more productive? It didn't really understand FRP until I read about Gregory's FrTime, by the time I realized my stuff was similar. There is still a lot of opportunity for bringing FRP-like constructs to mainstream programmers; e.g., through Bling. But I'm curious to see where the more formal approaches are going.

At anyrate, I think physics is the next frontier to be explored. We know how to abstract over time or make time a first-class value, but now can abstract over integrated time? In other words, rather than having "t", you have dt, and some fancy integration algorithm like Euler, RK4, or something else inside your interpreter to perform a nice dynamic simulation.

FRP Directions

Sean McDirmid: There seem to be various approaches ranging from formal to less formal, its unclear if the less formal systems (e.g., SuperGlue) can be considered FRP.

First of all, thanks for replying, Sean! Second of all, where can I download SuperGlue? :-) I've been wanting to ever since reading your paper with the embedded movies! Thirdly, I absolutely consider SuperGlue to be an example of FRP, and only didn't link to it because, as far as I can tell, there's no public implementation to link to, which is a shame.

Sean McDirmid: I have a hard time understanding formal FRP because it often seems to just be fighting against the purity straight jacket that Haskell puts you in. And how does purity make programmers more productive?

That's true for Reactive and other Haskell FRP systems, but obviously, FrTime isn't pure, React in OCaml isn't pure, etc. So what you see is indeed an effort to talk about time in referentially transparent terms in Haskell, and it leads to interesting results like Conal's "Simply efficient," in which he claims to have arrived at a garbage-collection friendly system, and Luke Palmer's, in which he concludes that you can't get where he wants to go in Haskell and so begins a new language design.

As for how purity makes programmers more productive, I think that there's an unfortunate initial learning curve, but after that, ensuring that your system is consistently referentially transparent has significant productivity benefits. But this observation is rather obviously anecdotal.

Sean McDirmid: here is still a lot of opportunity for bringing FRP-like constructs to mainstream programmers; e.g., through Bling. But I'm curious to see where the more formal approaches are going.

Agreed on all counts.

At anyrate, I think physics is the next frontier to be explored. We know how to abstract over time or make time a first-class value, but now can abstract over integrated time? In other words, rather than having "t", you have dt, and some fancy integration algorithm like Euler, RK4, or something else inside your interpreter to perform a nice dynamic simulation.

I see by following the link that Conal replied to those very issues in that thread, and that he has tackled the issue of continuous time in Reactive, so I don't know that I have anything to add here. It would also be interesting to hear what Luke Palmer thinks of the issues in the context of Dana.

I learned a long time ago...

First of all, thanks for replying, Sean! Second of all, where can I download SuperGlue? :-) I've been wanting to ever since reading your paper with the embedded movies! Thirdly, I absolutely consider SuperGlue to be an example of FRP, and only didn't link to it because, as far as I can tell, there's no public implementation to link to, which is a shame.

I learned from a long time ago (~Jiazzi) that just releasing something doesn't make it useful, and actually, can lead to lots of misunderstandings. SuperGlue is a demo vs. something to release, there are bugs when you hit certain keys, the library support is shallow (to support the examples in the OOPSLA paper), and of course always the performance problems that I talked about in the paper. The source code for SuperGlue was hanging around for a long time on the Lamp SVN server, but its probably been moved somewhere else now. I'll dig it up and publish it if you'd like, but I don't have time to move it forward to a release quality project. Bling is where my future effort is going for now, as it is much more useful in the near term (let's get more of FRP in the mainstream!). I hope I time and need to explore live programming again someday, heartbreaking that there is so much stuff to explore these days and no time to do it!

I'm not sure if SuperGlue can be considered an example of FRP. The dependency propagation algorithms that I use are a bit too pragmatic and I don't worry about glitches. But the biggest reason SuperGlue might not be FRP is that its not functional at all, rather its declarative/connection-based (ya, F often means D but not necessarily) without functions. If anything, SuperGlue was moving closer towards a declarative constraint system. I never could figure out why the FRP people didn't want to cite/compare against constraint language work (or vice versa with newer update propagation work). I think I am just missing some fundamental concept in FRP that makes it totally unrelated with constraints.

I see by following the link that Conal replied to those very issues in that thread, and that he has tackled the issue of continuous time in Reactive, so I don't know that I have anything to add here. It would also be interesting to hear what Luke Palmer thinks of the issues in the context of Dana.

I didn't really understand Conal's reply, but probably he is just way smarter than me :). The problem I see is that all efficient dynamic simulation techniques are based on discrete time steps, and there are a lot of techniques out there (I'm playing with Verlet now). I'm trying to absorb as much of the software physics work as possible, they just have so many clever ideas in that field that absorption will probably take forever! If we can provide language support for physics, it would be a nice cross over between SIGPLAN and SIGGRAPH.

What is FRP, etc.

Sean McDirmid: SuperGlue is a demo vs. something to release, there are bugs when you hit certain keys, the library support is shallow (to support the examples in the OOPSLA paper), and of course always the performance problems that I talked about in the paper. The source code for SuperGlue was hanging around for a long time on the Lamp SVN server, but its probably been moved somewhere else now. I'll dig it up and publish it if you'd like, but I don't have time to move it forward to a release quality project.

I thought the point behind releasing was to hope others in the community would help! :-) Also, how can we tell if it's FRP enough or not otherwise? ;-)

Sean McDirmid: But the biggest reason SuperGlue might not be FRP is that its not functional at all, rather its declarative/connection-based (ya, F often means D but not necessarily) without functions. If anything, SuperGlue was moving closer towards a declarative constraint system. I never could figure out why the FRP people didn't want to cite/compare against constraint language work (or vice versa with newer update propagation work). I think I am just missing some fundamental concept in FRP that makes it totally unrelated with constraints.

Peter Van Roy would tell you: it's not unrelated. :-)

Sean McDirmid: I didn't really understand Conal's reply, but probably he is just way smarter than me :)

I certainly have that problem!

Sean McDirmid: I'm trying to absorb as much of the software physics work as possible, they just have so many clever ideas in that field that absorption will probably take forever!

Quite right. I didn't mean to imply that there's nothing more to learn and that Reactive answers all the questions. Only that it might serve as a more effective launching-off point than we currently realize. And that, in a nutshell, is what I appreciate about FRP in a pure context. I myself am not a Haskell programmer, but I like that the Haskell community is out there, keeping us honest in terms of our semantics, while the OCamlRTs, Reacts, FrTimes, Flapjax, SuperGlues, etc. get to be pragmatic.

Need to find time to update

Need to find time to update the SuperGlue prototype to the current versions of Scala and Eclipse, then I'll put it out. I've been playing a lot with the DLR lately, this is really cool: you can easily generate code to be JIT'ed that is lightweight; e.g., the function pointers will get garbage collected when no longer in use. This means I can do Live Programming the right way...The next version of SuperGlue (or whatever replaces it) is definitely going to be much much better/faster/real. Now I just need the time.

Two more useful

Two more useful perspectives: clocks (perhaps even reified, first-class ones) and STM (it's interesting to compare transactional steps for Java, Esterel, and FRP and how to exploit them).

This is an interesting space. I've been thinking about the above for achieving implicit and explicit parallelism as a performance-related carrot to motivate such rethinking of our basic sequencing/coordination primitives.

Frp needs more experiments

W.r.t to Luke's frustrations, it seems indeed hard to get pure efficient implementations without space/time leaks. However in non pure languages, FrTime has shown the way (albeit I'm wary about their transparent lifting of functions and experiments in flapjax seem to indicate that's not necessarily needed).

To me frp seems to be the right way to handle reactive programs in functional languages: it moves the imperative bits at the I/O boundary of your program and leaves you with a purely functional program inside. But in order to get traction frp needs more experiments with real examples. More guidelines about when it's suitable or not, about how we structure frp interfaces/programs, how we handle feedback loops, how we integrate temporal and non temporal aspects, etc.

For example the time component of frp and the nice integration toy examples makes it look as a good choice to implement a physics engine, but early experiment of mine seems to indicate that it is a bad idea (because collision detection and response are dirty bits w.r.t. to time) -- however an frp interface to a physics engine could be the right way to get info out of the engine.

Thus to foster experiments I'd like to take this opportunity to publicize the frp core module react I recently released for OCaml (see this message for a comparison to the seemlingly defunct project ocamlrt). Hope to see some people get their hands on it (depends only on the ocaml distribution) and make experiments with it -- it will only take you a few lines to get signals/events to your input devices via ocamlsdl (or if you are in that kind of stuff there's an ANSI command line breakout clone in the distribution examples); if you want to handle real time also have a look to the experimental module rtime.

Very Interesting!

Thanks for react! I look forward to taking it for a spin. I'm especially interested in the relationship to real time as, again, I'm primarily interested in exploring Nick Szabo's insight that his contract language is essentially a real-time-based reactive one.

Nice

Wow, I'm glad OCamlRT was useful for someone. I gave up working on it about a year ago at the behest of my advisor ("who uses OCaml?"). FWIW I've moved the sources (along with myself) to http://cs.brown.edu/~squirrel/temp/ocamlrt2.tgz, since at least a few people seem to miss it.

React looks pretty solid, I hope sometime I get a chance to play with it.

Re compute-expensive "dirty bits"... you want an async_map function (over events). Unlike map, its input and output events are not causally related... the output event occurs in its own distinct time step whenever the computation completes. Works well for I/O too.

Dirty bits are really dirty

The dirty bits I mention are not related to computational intensiveness, they are dirty w.r.t. to time itself. When you do continuous collision detection in frp, the problem is that when you realize that your object's position went too far you already computed it and made it visible to the outside world, to prevent that you have to dismiss this position, but then you get further problems with collision response.

I didn't research that extensively (and already forgot the details of my unsucessfull findings) but it seems hard to get an elegant and efficient solution. Reading about physics engine implementations made me feel that it doesn't fit well in the frp framework because during a "dt" it needs to play with time (and hence positions) internally and then in the end communicate the resulting position for this "dt". Thus the suggestion that an frp interface may be more suited than an implementation in frp itself. But I'd love the be proven wrong.

Best,

P.S. Don't forget that an advisor is just that...

Perhaps Conal's new paper on

Perhaps Conal's new paper on automatic differentiation is related to the physics problem. I can see it being useful in expressing physical constraints, even if these constraints are then solved via discrete integration.

1. The implementation of the

1. The implementation of the physics engine and how to expose it are different. FRP is a clean interface to it, giving a lot of wiggle room in the implementation. E.g., you can play with parallel streams, fusion (dipping/lowering work, or lucid/synchrone tricks), precomputation (schedule your animation) and QoS (drop frames), specialization, etc. To my knowledge, except for FrTime, FRP engines haven't really been optimized (likely because our collective interest in getting the abstractions right first), but that's one of their big appeals.

2. I'm not sure I understand the dirty bit problem. The implementation (w or w/out signals) can likely have dirty bits encoded inside, and only clean values are exposed. If you coded the engine with signals itself, that might even be as simple as a case of merge/filter/hold -- this is a common pattern, such as for lifting object oriented code (MrEd, the DOM, etc.).

3. There's a cost to dirty bits in a parallel system; perhaps you can refine what you intend them for, algorithmically?

2. I'm not sure I understand

2. I'm not sure I understand the dirty bit problem. The implementation (w or w/out signals) can likely have dirty bits encoded inside, and only clean values are exposed. If you coded the engine with signals itself, that might even be as simple as a case of merge/filter/hold -- this is a common pattern, such as for lifting object oriented code (MrEd, the DOM, etc.).

I think the problem that dbuenzli is referring to is specific to physics: because your time step is discrete, you have the problem where one object can pass through another if it moves completely through it in one time step. In this case, collection detection occurs by assuming the object takes the shape of its entire movement for that time step. Actually, real physics engines are all about apply and re-applying constraints on every time step until the system stabilizes.

I really admire people like Erin Catto who really have a handle on these problem; I get lost beyond Gauss-Seidel stabilization, this is really hardcore math and its still all real (e.g., implemented and fast)! Can we PL'ers learn from these systems? Yes! What can we PL'ers bring to the table? Abstraction, of course. An FRP candy shell can make it much easier to use could make this stuff more accessible; i.e., we could apply more physics to UI programming (writing a paper on that topic right now).

Ah, that makes more sense.

Ah, that makes more sense. One cool direction is stuff like continuous time languages ( http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/ptolemy/domains/ct/doc/body.htm ), though I haven't had a chance to look at them yet.

One nice feature of Ptolemy is that it has pluggable levels of models; you might be able to use CT to write your physics engine, and then export the values into a SDF framework (e.g., most FRP systems).

please keep us informed

we could apply more physics to UI programming (writing a paper on that topic right now).

Definitely, I'm working on a

Definitely, I'm working on a draft to submit to UIST 09 (deadline March 30th), I'll try to have an early draft ready for early review in a couple of weeks. I've never tried writing an HCI paper before, so this is an interesting learning experience.