Relative time FRP

Conal seems to have discovered an essential change in the semantics of FRP. The change is to think in terms of relative time instead of absolute time (Einstein would approve). It really cleans a lot of things in the semantics up, makes the implementation local (which functional programming is very good at making efficient).

So, for example, instead of Behavior a = Time -> a, we have Behavior a = Time -> a :-). The difference is simply that on the left, “now” is whatever time you give it, whereas on the right, “now” is 0.

However, this change has far reaching consequences on how I think about FRP. The difficulties I have been trying to overcome in my implementations no longer make any sense. This is a good sign.

I have been gradually hacking on a “practical” implementation of FRP, i.e. putting aside the beauty of the implementation and doing whatever I can to make it efficient and easy to use. But man it’s awful. I have no certainty whatsoever than the 200 lines I have so far written are anywhere near correct other than they seem to work when I play with them. I don’t like that feeling.

I have the urge to revisit my precise and rigorous implementations I had been working on, which I gave up on because they didn’t efficiently express what I wanted them to. In particular, this relative time thing with comonads seems very simple. So I want to write it together with my “correct blocking thunks”, which are thunks that are technically blocking, but they never actually do because you have to prove that they won’t before you evaluate them :-)

I’m pretty excited. I’m hopeful that this new FRP is expressive and powerful in addition to its beauty. I won’t know that until I rewire my brain a little.

About these ads

5 thoughts on “Relative time FRP

  1. Great to hear that absolute time in FRP is finally under wider discussion – are Conal’s remarks in that direction online?

    You might be interested in some aspects of my old FunWorlds project (currently in my top 2 of projects I’d like to revive and continue, if I had the funds;-), especially the later, OpenGL-based version (although the paper for the old VRML-based version had some useful history in it):

    project(s): http://www.cs.kent.ac.uk/~cr3/FunWorlds/

    slides: http://www.cs.kent.ac.uk/~cr3/talks/ (look for FunWorlds; the VRML version is fun, but the OpenGL version mentions my concerns about Fran’s time approach)

    I should at least update that old code for current GHC, but I’d be very interested to know how much of my old stuff I can just get from the new wave of reactive/fieldtrip (certainly the scenegraph, but if you’re right, I might no longer need my own FRP).

    PS. people who prefere relative time over absolute also prefer Petri-nets over automata, so you might like my notes here:

    http://www.cs.kent.ac.uk/~cr3/talks/index.html#PetriNets

  2. I’ve been thinking about this myself, recently. I’ve been thinking lately that Reactive’s main semantic problem is that it doesn’t enforce causality (i.e. that later values should be functions only of earlier values). Relative time is a step in that direction, but you really need a way to specify both relative and non-negative before you get the big advantages, like being able to eliminate delayOccs.

  3. Ah, I missed that. Yes, the distinction I was thinking of is between global time, passed in from above in behaviours (and somehow magically arrived at in events), and local time, emerging purely from local clocks (though time from a reference clock could be passed around explicitly, like other behaviours one wants to refer to).

    In FunWorlds FRP, a behavior is a description of an experiment; sampling the behaviour gives a current value and a residual behaviour (the latter replacing the original behaviour; Conal did abandon his own experiments in that direction). That does imply that local clocks (integrating over some constant), start from zero, but it is somewhat more radical than the move from absolute to relative time discussed here. My misinterpretation.

    On the other hand, this radical departure worked out well (for the examples I tried, in particular those involving reactivity) and is definitely something I’d like to keep in a revived version.

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