comparison 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
comparison
equal deleted inserted replaced
418:ad7e854a518c 419:cb5897276abf
1 functor Make(M : sig
2 type data
3 val inj : sql_injectable data
4 end) = struct
5
6 type ref = int
7
8 sequence s
9 table t : { Id : int, Data : M.data }
10
11 fun new d =
12 id <- nextval s;
13 () <- dml (INSERT INTO t (Id, Data) VALUES ({id}, {d}));
14 return id
15
16 fun read r =
17 o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {r});
18 return (case o of
19 None => error <xml>You already deleted that ref!</xml>
20 | Some r => r.T.Data)
21
22 fun write r d =
23 dml (UPDATE t SET Data = {d} WHERE Id = {r})
24
25 fun delete r =
26 dml (DELETE FROM t WHERE Id = {r})
27 end