diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-10-23 17:35:10 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-10-23 17:35:10 -0400 |
commit | 2a398adce5d872b559f6fe02eaa55427e4756ac7 (patch) | |
tree | 5de8de2f16499f80ffe6cd1cb7bc2afb6ca851d4 /demo/refFun.ur | |
parent | a4a697ab04bac663206a54292d73f67ca895c243 (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.ur | 27 |
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 |