annotate 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
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@419 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@419 27 end