summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 14:57:33 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 14:57:33 -0400
commite1618fb012b5926889d80893c9ac4ce08838519d (patch)
tree46b157b5c6fb6967e1ab4809f94a6d6505de7411 /demo
parentddac92a3d792b7e7342e4003862cd5ff5c1f0ab8 (diff)
outer demo
Diffstat (limited to 'demo')
-rw-r--r--demo/cookie.urp1
-rw-r--r--demo/form.urp1
-rw-r--r--demo/outer.ur35
-rw-r--r--demo/outer.urp4
-rw-r--r--demo/outer.urs1
-rw-r--r--demo/prose4
6 files changed, 44 insertions, 2 deletions
diff --git a/demo/cookie.urp b/demo/cookie.urp
index 61a1a1e0..9e283d4b 100644
--- a/demo/cookie.urp
+++ b/demo/cookie.urp
@@ -1,3 +1,2 @@
-debug
cookie
diff --git a/demo/form.urp b/demo/form.urp
index f28331fc..73356d49 100644
--- a/demo/form.urp
+++ b/demo/form.urp
@@ -1,3 +1,2 @@
-debug
form
diff --git a/demo/outer.ur b/demo/outer.ur
new file mode 100644
index 00000000..ac49f475
--- /dev/null
+++ b/demo/outer.ur
@@ -0,0 +1,35 @@
+table t : { Id : int, B : string }
+ PRIMARY KEY Id
+
+table u : { Id : int, Link : int, C : string, D : option float }
+ PRIMARY KEY Id,
+ CONSTRAINT Link FOREIGN KEY Link REFERENCES t(Id)
+
+fun main () =
+ xml <- queryX (SELECT t.Id, t.B, u.Id, u.C, u.D
+ FROM t LEFT JOIN u ON t.Id = u.Link)
+ (fn r => <xml><tr>
+ <td>{[r.T.Id]}</td>
+ <td>{[r.T.B]}</td>
+ <td>{[r.U.Id]}</td>
+ <td>{[r.U.C]}</td>
+ <td>{[r.U.D]}</td>
+ </tr></xml>);
+ return <xml><body>
+ <table>{xml}</table>
+
+ <form>Insert into t: <textbox{#Id} size={5}/> <textbox{#B} size={5}/>
+ <submit action={addT}/></form>
+ <form>
+ Insert into u: <textbox{#Id} size={5}/> <textbox{#Link} size={5}/> <textbox{#C} size={5}/>
+ <textbox{#D} size={5}/> <submit action={addU}/>
+ </form>
+ </body></xml>
+
+and addT r =
+ dml (INSERT INTO t (Id, B) VALUES ({[readError r.Id]}, {[r.B]}));
+ main ()
+
+and addU r =
+ dml (INSERT INTO u (Id, Link, C, D) VALUES ({[readError r.Id]}, {[readError r.Link]}, {[r.C]}, {[readError r.D]}));
+ main ()
diff --git a/demo/outer.urp b/demo/outer.urp
new file mode 100644
index 00000000..994c3e1a
--- /dev/null
+++ b/demo/outer.urp
@@ -0,0 +1,4 @@
+database dbname=test
+sql outer.sql
+
+outer
diff --git a/demo/outer.urs b/demo/outer.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/demo/outer.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page
diff --git a/demo/prose b/demo/prose
index 2d4f5ea3..2cfbb291 100644
--- a/demo/prose
+++ b/demo/prose
@@ -135,6 +135,10 @@ constraints.urp
<li>The <tt>FOREIGN KEY</tt> constraint declares that a row of the table references a particular column of another table, or of the same table, as we see in this example. It's a static type error to reference a foreign key column that has no <tt>PRIMARY KEY</tt> or <tt>UNIQUE</tt> constraint.</li>
</ol>
+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>
+
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>