changeset 1573:34364e383bed

For new IF, fix Monoize typing and add to manual
author Adam Chlipala <adam@chlipala.net>
date Sat, 15 Oct 2011 09:04:41 -0400 (2011-10-15)
parents 5530a8075b62
children 644558d9c756
files doc/manual.tex src/monoize.sml tests/sql_if.ur tests/sql_if.urp tests/sql_if.urs
diffstat 5 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/doc/manual.tex	Fri Oct 14 02:33:03 2011 -0430
+++ b/doc/manual.tex	Sat Oct 15 09:04:41 2011 -0400
@@ -1783,6 +1783,15 @@
 \hspace{.1in} \to \mt{nullify} \; \mt{t} \; \mt{nt} \to \mt{sql\_query} \; \mt{tables} \; \mt{agg} \; [\mt{nm} = \mt{t}] \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{nt}
 \end{array}$$
 
+There is also an \cd{IF..THEN..ELSE..} construct that is compiled into standard SQL \cd{CASE} expressions.
+$$\begin{array}{l}
+\mt{val} \; \mt{sql\_if\_then\_else} : \mt{tables} ::: \{\{\mt{Type}\}\} \to \mt{agg} ::: \{\{\mt{Type}\}\} \to \mt{exps} ::: \{\mt{Type}\} \to \mt{t} ::: \mt{Type} \\
+\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{bool} \\
+\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t} \\
+\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t} \\
+\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t}
+\end{array}$$
+
 \texttt{FROM} clauses are specified using a type family, whose arguments are the free table variables and the table variables bound by this clause.
 $$\begin{array}{l}
   \mt{con} \; \mt{sql\_from\_items} :: \{\{\mt{Type}\}\} \to \{\{\mt{Type}\}\} \to \mt{Type} \\
@@ -2133,6 +2142,7 @@
   &&& E \; b \; E & \textrm{binary operators} \\
   &&& \mt{COUNT}(\ast) & \textrm{count number of rows} \\
   &&& a(E) & \textrm{other aggregate function} \\
+  &&& \mt{IF} \; E \; \mt{THEN} \; E \; \mt{ELSE} \; E & \textrm{conditional} \\
   &&& (Q) & \textrm{subquery (must return a single expression column)} \\
   &&& (E) & \textrm{explicit precedence} \\
   \textrm{Nullary operators} & n &::=& \mt{CURRENT\_TIMESTAMP} \\
--- a/src/monoize.sml	Fri Oct 14 02:33:03 2011 -0430
+++ b/src/monoize.sml	Sat Oct 15 09:04:41 2011 -0400
@@ -2816,9 +2816,9 @@
                 val s = (L'.TFfi ("Basis", "string"), loc)
                 fun sc s = (L'.EPrim (Prim.String s), loc)
             in
-                ((L'.EAbs ("if", s, (L'.TFun (s, s), loc),
+                ((L'.EAbs ("if", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
                            (L'.EAbs ("then", s, (L'.TFun (s, s), loc),
-                                     (L'.EAbs ("else", s, (L'.TFun (s, s), loc),
+                                     (L'.EAbs ("else", s, s,
                                                strcat [sc "(CASE WHEN (",
                                                        (L'.ERel 2, loc),
                                                        sc ") THEN (",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sql_if.ur	Sat Oct 15 09:04:41 2011 -0400
@@ -0,0 +1,6 @@
+table t : { A : int, B : int }
+
+fun main () =
+    x <- queryX (SELECT * FROM t WHERE IF t.A = 6 THEN t.B < 2 ELSE t.B > 5)
+                (fn r => <xml><li>{[r.T.A]}, {[r.T.B]}</li></xml>);
+    return <xml><body>{x}</body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sql_if.urp	Sat Oct 15 09:04:41 2011 -0400
@@ -0,0 +1,4 @@
+database dbname=sql_if
+sql sql_if.sql
+
+sql_if
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sql_if.urs	Sat Oct 15 09:04:41 2011 -0400
@@ -0,0 +1,1 @@
+val main : unit -> transaction page