aboutsummaryrefslogtreecommitdiffhomepage
path: root/demo/refFun.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 17:35:10 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 17:35:10 -0400
commitda7b52ba28367cf2b31476e77e1a26e53e4765e4 (patch)
tree5de8de2f16499f80ffe6cd1cb7bc2afb6ca851d4 /demo/refFun.ur
parenta2495d384c7747a079cb0f4bc31f44d626391068 (diff)
Fix bug with bringing functor argument instances into scope; Ref demo, minus prose
Diffstat (limited to 'demo/refFun.ur')
-rw-r--r--demo/refFun.ur27
1 files changed, 27 insertions, 0 deletions
diff --git a/demo/refFun.ur b/demo/refFun.ur
new file mode 100644
index 00000000..d58acee5
--- /dev/null
+++ b/demo/refFun.ur
@@ -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