From 850563d90f0f66b9563e0e0c9a24eac6bf78df7e Mon Sep 17 00:00:00 2001 From: TheNotary Date: Fri, 21 Oct 2016 14:06:41 -0500 Subject: reflows intro tutorial --- demo/prose | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 15 deletions(-) (limited to 'demo') diff --git a/demo/prose b/demo/prose index 8637ef68..7c45a267 100644 --- a/demo/prose +++ b/demo/prose @@ -1,38 +1,81 @@

Ur/Web is a domain-specific language for programming web applications backed by SQL databases. It is (strongly) statically-typed (like ML and Haskell) and purely functional (like Haskell). Ur is the base language, and the web-specific features of Ur/Web (mostly) come only in the form of special rules for parsing and optimization. The Ur core looks a lot like Standard ML, with a few Haskell-isms added, and kinder, gentler versions added of many features from dependently-typed languages like the logic behind Coq. The type system is much more expressive than in ML and Haskell, such that well-typed web applications cannot "go wrong," not just in handling single HTTP requests, but across their entire lifetimes of interacting with HTTP clients. Beyond that, Ur is unusual in using ideas from dependent typing to enable very effective metaprogramming, or programming with explicit analysis of type structure. Many common web application components can be built by Ur/Web functions that operate on types, where it seems impossible to achieve similar code re-use in more established statically-typed languages.

-

This demo is built automatically from Ur/Web sources and supporting files. If you unpack the Ur/Web source distribution, then the following steps will (if you're lucky) build you a local version of this demo. If you're not lucky, you can consult the beginning of the manual for more detailed instructions. +

The page you are currently reading is a part of the demo included with the Ur/Web sources and supporting files available from github. The following steps will build a local instance of the demo if you're lucky (and running a debian based linux OS). If you're not lucky, you can consult the beginning of the manual for more detailed instructions.

-
./configure
+
Install System Dependencies
+

+

sudo apt-get install build-essential \
+  emacs-goodies-el \
+  libgmp-dev \
+  libssl-dev \
+  libpq-dev \
+  libsqlite3-dev \
+  mlton \
+  sqlite3

+ +
Build and install the Ur/web Framework
+

./configure
 make
 sudo make install
-urweb -noEmacs -demo /Demo demo

+

-

The -demo /Demo flag says that we want to build a demo application that expects its URIs to begin with /Demo. The final argument demo gives the path to a directory housing demo files. One of the files in that directory is prose, a file describing the different demo pieces with HTML. Some lines of prose have the form foo.urp, naming particular project files (with the extension .urp) in that directory.

+
Compile the demo the easy way
+

$ urweb -dbms sqlite -db /path_to_db.sqlite -demo /Demo demo
+

-

These project files can also be built separately. For example, you could run +

The -dbms sqlite flag indicates that instead of using the default database management system of postgres, we wish to use sqlite (not good for production). The -db flag allows us to specify the path to our sqlite database on the file system. The -demo /Demo parameter indicates that we want to build a demo application that expects its URIs to begin with /Demo. The final argument demo gives the path to a directory housing Ur/Web source files (.ur, .urp, .urs, etc, etc). +

-
urweb demo/hello
+

+The following files are created during the compile process: +

+

+ +
Migrate the Database
+

+When we compiled the demo in the above step, a demo.sql file was created for us which contains all the information required to create a database congruent with the demo web app. The below command will provision our sqlite database. Also of interest is the file demo.urp which contains a database line with the PostgreSQL database that the demo web server will try to connect to if database information isn't provided as command line arguments when the webapp is compiled. -to build the "Hello World" demo application. Whether building the pieces separately or all at once with the -demo flag, a standalone web server executable is generated. The -demo command line will generate demo/demo.exe, and the other command line will generate demo/hello.exe. Either can be run with no arguments to start a single-threaded server accepting requests on port 8080. Pass the flag -h to see which options are available.

+
$ sqlite3 /path/to/database/file <demo/demo.sql
+
+

-

The -demo version also generates some HTML in a subdirectory out of the demo directory. It is easy to set Apache up to serve these HTML files, and to proxy out to the Ur/Web web server for dynamic page requests. This configuration works for me, where DIR is the location of an Ur/Web source distribution. +

Boot the web app
+Executing the binary generated above (demo/demo.exe) with no arguments will start a single-threaded server listening on port 8080. Pass the flag -h to see which options are available on such freshly built binaries. +

+

$ demo/demo.exe
+Database connection initialized.
+Listening on port 8080....
+
+Test out http://localhost:8080/Demo/Demo/main which should consist of links to the individual demos after booting the web app.

+

+ +
Serve the Static Content with a Reverse Proxy
+

The -demo version also generates some HTML in a subdirectory out of the demo directory (eg index.html). It is easy to set Apache up to serve these HTML files, and to proxy out to the Ur/Web web server for dynamic page requests. This configuration works for me, where DIR is the location of an Ur/Web source distribution.

Alias /demo/ "DIR/demo/out/"
 
 ProxyPass /Demo/ http://localhost:8080/Demo/
 ProxyPassReverse /Demo/ http://localhost:8080/Demo/

-

Building the demo also generates a demo.sql file, giving the SQL commands to run to define all of the tables and sequences that the applications expect to see. The file demo.urp contains a database line with the PostgreSQL database that the demo web server will try to connect to.

-

The easiest way to get a demo running locally is probably with this alternate command sequence: +

Compile Individually
+

These project files can also be built separately. For example, you could run + +

$ urweb demo/hello
+
-
urweb -dbms sqlite -db /path/to/database/file -demo /Demo demo
-sqlite3 /path/to/database/file <demo/demo.sql
-demo/demo.exe

+to build the "Hello World" demo application. Doing so will invite urweb to seak out the various demo/hello.* files and, from them, build a binary demo/demo.exe. The URL to access the resulting webapp will be http://localhost:8080/Hello/main. +

-

Then you can skip the static content and connect directly to the demo server at http://localhost:8080/Demo/Demo/main, which contains links to the individual demos. If you're running the server created just for hello, then the URL will be http://localhost:8080/Hello/main.

+
This File
+

One of the files in the demo directory is named prose, a file describing the different demo pieces with HTML. Some lines of prose have the form foo.urp, naming particular project files (with the extension .urp) in that directory. These makeup the different pages of the tutorial.

-

The rest of the demo focuses on the individual applications. Follow the links in the lefthand frame to visit the applications, commentary, and syntax-highlighted source code. (An Emacs mode is behind the syntax highlighting.) I recommend visiting the applications in the order listed, since that is the order in which new concepts are introduced.

+
Proceeding Demo Exhibits
+

The rest of the demo focuses on the individual facets of the Ur/ Web framework. Follow the links in the lefthand frame to visit the applications, commentary, and syntax-highlighted source code. (An Emacs mode is behind the syntax highlighting.) I recommend visiting the applications in the order listed, since that is the order in which new concepts are introduced.

hello.urp -- cgit v1.2.3