annotate demo/refFun.ur @ 442:9095a95a1bf9

Don't inline case expressions
author Adam Chlipala <adamc@hcoop.net>
date Thu, 30 Oct 2008 15:39:06 -0400
parents c471345f5165
children 20fab0e96217
rev   line source
adamc@419 1 functor Make(M : sig
adamc@419 2 type data
adamc@419 3 val inj : sql_injectable data
adamc@419 4 end) = struct
adamc@419 5
adamc@419 6 type ref = int
adamc@419 7
adamc@419 8 sequence s
adamc@419 9 table t : { Id : int, Data : M.data }
adamc@419 10
adamc@419 11 fun new d =
adamc@419 12 id <- nextval s;
adamc@434 13 dml (INSERT INTO t (Id, Data) VALUES ({id}, {d}));
adamc@419 14 return id
adamc@419 15
adamc@419 16 fun read r =
adamc@419 17 o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r});
adamc@419 18 return (case o of
adamc@419 19 None => error <xml>You already deleted that ref!</xml>
adamc@419 20 | Some r => r.T.Data)
adamc@419 21
adamc@419 22 fun write r d =
adamc@419 23 dml (UPDATE t SET Data = {d} WHERE Id = {r})
adamc@419 24
adamc@419 25 fun delete r =
adamc@419 26 dml (DELETE FROM t WHERE Id = {r})
adamc@420 27
adamc@419 28 end