# HG changeset patch # User Adam Chlipala # Date 1236698281 14400 # Node ID 1b571a05874cbc84bed47a5981b6ed950d969ced # Parent 8e17e6b615bdfee03ac02df16f5cf3820dad363a React demo diff -r 8e17e6b615bd -r 1b571a05874c demo/prose --- a/demo/prose Tue Mar 10 10:49:18 2009 -0400 +++ b/demo/prose Tue Mar 10 11:18:01 2009 -0400 @@ -191,3 +191,9 @@

Ur/Web makes it easy to write code whose execution should be distributed between the web server and client web browsers. Server-side code is compiled to efficient native code, and client-side code is compiled to JavaScript. Ur/Web programmers don't need to worry about these details, because the language and standard library provide a uniform ML-like interface for the whole process.

Here's an example of a button that, when clicked, opens an alert dialog on the client.

+ +react.urp + +

Most client-side JavaScript programs modify page contents imperatively, but Ur/Web is based on functional-reactive programming instead. Programs allocate data sources and then describe the page as a pure function of those data sources. When the sources change, the page changes automatically.

+ +

Here's an example where a button modifies a data source that affects some text on the page. The affected portion of the page is indicated with the pseudo-HTML tag dyn, whose signal attribute specifies one of these pure functions over mutable sources. A source containing data of type t has type source t and is created with the source operation within the transaction monad. Functions over sources are represented in the monad signal. Like in Haskell, we overload monad notations, so that the same return and bind operators can be used to write signals and transactions. The signal function coerces a source to a signal.

diff -r 8e17e6b615bd -r 1b571a05874c demo/react.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/react.ur Tue Mar 10 11:18:01 2009 -0400 @@ -0,0 +1,6 @@ +fun main () = + s <- source "You didn't click it yet."; + return +