aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 15:13:00 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 15:13:00 -0400
commit92df298250032469bab59565aa4e23a86b4a6e9a (patch)
treec54594176882d7af9f080be01b96b084bd8b7434
parente1618fb012b5926889d80893c9ac4ce08838519d (diff)
view demo
-rw-r--r--demo/prose4
-rw-r--r--demo/view.ur25
-rw-r--r--demo/view.urp4
-rw-r--r--demo/view.urs1
4 files changed, 34 insertions, 0 deletions
diff --git a/demo/prose b/demo/prose
index 2cfbb291..aa12af6e 100644
--- a/demo/prose
+++ b/demo/prose
@@ -139,6 +139,10 @@ outer.urp
<p>SQL outer joins are no problem, as this demo shows. Unlike with SQL, here we have static type inference determining for us which columns may become nullable as a result of an outer join, and the compiler will reject programs that make the wrong assumptions about that process. The details of that nullification don't appear in this example, where the magic of type classes determines both the post-join type of each field and the right pretty-printing and parsing function for each of those types.</p>
+view.urp
+
+<p>SQL views are also supported with a special declaration form, analogous to <tt>table</tt>. A multi-parameter type class <tt>fieldsOf</tt> is used to characterize places where both tables and views are allowed. For instance, the polymorphic function <tt>list</tt> shown here lists the contents of any table or view containing just a single <tt>int</tt> column named <tt>A</tt>.</p>
+
sum.urp
<p>Metaprogramming is one of the most important facilities of Ur. This example shows how to write a function that is able to sum up the fields of records of integers, no matter which set of fields the particular record has.</p>
diff --git a/demo/view.ur b/demo/view.ur
new file mode 100644
index 00000000..ce1242e0
--- /dev/null
+++ b/demo/view.ur
@@ -0,0 +1,25 @@
+table t : { A : int }
+view v = SELECT t.A AS A FROM t WHERE t.A > 7
+
+fun list (u ::: Type) (_ : fieldsOf u [A = int]) (title : string) (x : u) =
+ xml <- queryX (SELECT * FROM x)
+ (fn r : {X : {A : int}} => <xml><li>{[r.X.A]}</li></xml>);
+ return <xml>
+ <h2>{[title]}</h2>
+ <ul>{xml}</ul>
+ </xml>
+
+fun main () =
+ listT <- list "T" t;
+ listV <- list "V" v;
+ return <xml><body>
+ {listT}
+ {listV}
+ <br/>
+
+ <form>Insert: <textbox{#A}/> <submit action={ins}/></form>
+ </body></xml>
+
+and ins r =
+ dml (INSERT INTO t (A) VALUES ({[readError r.A]}));
+ main ()
diff --git a/demo/view.urp b/demo/view.urp
new file mode 100644
index 00000000..0677e8bf
--- /dev/null
+++ b/demo/view.urp
@@ -0,0 +1,4 @@
+database dbname=test
+sql view.sql
+
+view
diff --git a/demo/view.urs b/demo/view.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/view.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page