[Ur] Ur/Web & RDP

Adam Chlipala adamc at impredicative.com
Sat Feb 25 15:57:13 EST 2012


Meta-answer to your question: Ur/Web is not like the typical programming 
language.  It embodies one particular vision (mine) for how web apps 
should be programmed, via features built into the compiler and runtime 
system.  It is not easy to go beyond this model (could be impossible 
without modifying the core language implementation), but you might find 
that the model already supports what you want.

David Barbour wrote:
> I'm very interested in Ur as a platform for a new (from 2010) impure 
> declarative programming model called `Reactive Demand Programming` (RDP).

Perhaps you could describe a simple RDP example that would be 
illustrative to implement in Ur/Web?  Much of your discussion is too 
abstract for me ATM.

> Are there any existing reactive models for Ur/Web?

The _only_ GUI model built into Ur/Web is one that I call reactive.  
Perhaps it would be helpful for you to go through the main demo:
     http://www.impredicative.com/ur/demo/
Reactive GUI features are used in all of the demo programs starting with 
"React."

> Arrows models? Adam Megacz's generalized arrows?

I'm not aware of anything done yet with arrows and Ur.

> If I do model generalized arrows, would it be easy to create something 
> like the Haskell `proc` syntax for pointy programming? (Point-free 
> programming is often sufficient, but is sometimes inconvenient.)

I'm not familiar with that Haskell notation.

> RDP doesn't require general dependent types, but it would be very 
> useful to represent `logical latency` in composition of certain types, 
> or at least to constrain by it. Would this be feasible with the 
> metaprogramming facilities?

Possibly.  I can give a better answer if you incorporate this in an 
example like I suggested above.

> Would it be difficult to upgrade an Ur/Web application at runtime? 
> I.e. support for staging, runtime compilation, specialization? I'd 
> like the server itself to be reactive, ultimately, and to support a 
> lot of live programming.

The only way to do live update now is to interpose a proxy that holds 
client connections while the old server process is exiting and a new one 
is starting.  Perhaps the functionality you want can be achieved in part 
by implementing an interpreter for a small language inside of Ur/Web.

> Does Ur support server-side parallelism? Is it easy to model 
> long-running processes and interact with them?

It's easy to start a server process with an arbitrary number of OS 
threads to handle client connections, and they all run in parallel.  
There is also support for periodic tasks, which run in their own 
threads, alternating between sleeping N seconds and running single 
transactions.  Ur/Web isn't currently designed for arbitrary server-side 
programming, but you might be surprised at what the standard model 
already provides, to the extent where you might not need to write new 
servers.

> What about client-side parallelism?

Ur/Web supports cooperative multi-threading in client-side code, which I 
call concurrency, but not parallelism, which can't be achieved in 
standard browser JavaScript, with its inherent serialization of code 
execution.

> RDP requires some non-traditional shared state models, especially to 
> resolve concurrent interaction with state. Ur/Web focuses on SQL with 
> its arbitrary serialization of updates, but would there be anything 
> preventing alternative state models?

No.  You can use the C FFI to implement something new and make it play 
nicely with transactions.  If you can't make it transactional, then to a 
first approximation it can't be made to work.

> How much of the client-side program is validated?

I'm not sure what you mean.  Client-side code all comes from 
type-checked Ur/Web code, unless you use the JavaScript FFI.  Beside my 
general aesthetic preferences for interfaces to standard resources, I 
try to follow some principles, like "strings are never implicitly 
interpreted as code."

> Any support for type-safe WebGL? or WebSockets? Or video?

No support for such things in the standard Ur/Web distribution now, and 
I'm not familiar with details of any of the 3, even in mainstream 
programming.

> I saw mention of AJAX and COMET, but I haven't looked much into it 
> yet. Would it be difficult to write a web-app that uses WebSockets for 
> server push, when they are available, and falls back to the more 
> hackish mechanisms otherwise?

You might be able to do various things with the C FFI, and it should 
also be possible to add a compiler option to implement RPCs and 
message-passing via alternate backend technologies (without requiring 
changes to application source).

> How efficient is the generated JavaScript code?

It's not at all tuned for maximum performance, but it's generally worked 
out well for me so far, on recent machines/browsers.



More information about the Ur mailing list