diff demo/refFun.ur @ 419:cb5897276abf

Fix bug with bringing functor argument instances into scope; Ref demo, minus prose
author Adam Chlipala <adamc@hcoop.net>
date Thu, 23 Oct 2008 17:35:10 -0400
parents
children 9119a5920106
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/refFun.ur	Thu Oct 23 17:35:10 2008 -0400
@@ -0,0 +1,27 @@
+functor Make(M : sig
+                 type data
+                 val inj : sql_injectable data
+             end) = struct
+
+    type ref = int
+
+    sequence s
+    table t : { Id : int, Data : M.data }
+
+    fun new d =
+        id <- nextval s;
+        () <- dml (INSERT INTO t (Id, Data) VALUES ({id}, {d}));
+        return id
+
+    fun read r =
+        o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r});
+        return (case o of
+            None => error <xml>You already deleted that ref!</xml>
+          | Some r => r.T.Data)
+
+    fun write r d =
+        dml (UPDATE t SET Data = {d} WHERE Id = {r})
+
+    fun delete r =
+        dml (DELETE FROM t WHERE Id = {r})
+end