archives

Declarative reactive tables

A declarative reactive table is something that I've invented for building continuous compilers/interpreters: its a table whose changes are not only observable, but the statements to access and populate the table are declarative, meaning their execution order is not important. The table is populated by statements that read like "e_table[e_k] = e_v", where e_table, e_k, and e_v are expressions that are both time-dependent (e.g., they contain continuous signals). An access is simply "e_table[e_k]", where e_table and e_k are expressions that are again time-dependent, while the result is also time dependent. A declarative reactive table is then the peer of a continuous signal, its accesses can be used as signals while it is populated via signal expressions. However, these tables aren't necessarily FRP, since I don't see how the population statements could be made composable.

Example: symbol tables in a continuous compiler are declarative reactive tables whose definition nodes in the AST act to populate the map while identifier reference nodes access the table. Then:

// define Foo
scopeA["Foo"] = FooType;
// define bar in Foo
FooType["bar"] = IntType;

// resolve x = Foo.bar
scopeB["x"] = scopeA["Foo"]["bar"]

Now, when we edit the definition of "Foo" so that it becomes named "Bob", x's type will be automatically recomputed so that it now undefined (unless there is another "Foo" hiding somewhere). Since AST nodes primarily communicate through symbol tables, we get most of what we need for a continuous type checker out of declarative reactive tables. Its even possible to augment an existing compiler to use these tables (which is what I did for Scala).

I'm wondering if anyone has seen a pattern like this before in a compiler implementation or perhaps another domain. I'm also wondering if I could generalize this somehow to FRP, maybe not the pure Haskell kind, but a system like FrTime or Flapjax.