comparison demo/more/versioned1.ur @ 993:10114d7b7477

SELECT DISTINCT; eta expansion during Cjrization
author Adam Chlipala <adamc@hcoop.net>
date Tue, 06 Oct 2009 15:39:27 -0400
parents
children 166ea3944b91
comparison
equal deleted inserted replaced
992:b825d843b22d 993:10114d7b7477
1 open Versioned.Make(struct
2 con key = [Id = int]
3 con data = [Nam = string, ShoeSize = int]
4
5 val key = {Id = _}
6 val data = {Nam = {Inj = _,
7 Eq = _},
8 ShoeSize = {Inj = _,
9 Eq = _}}
10 end)
11
12 fun expandKey k =
13 name <- source "";
14 shoeSize <- source "";
15 return {Key = k, Nam = name, ShoeSize = shoeSize}
16
17 fun main () =
18 ks0 <- keys;
19 ks0 <- List.mapM (fn r => expandKey r.Id) ks0;
20 ks <- source ks0;
21
22 id <- source "";
23 name <- source "";
24 shoeSize <- source "";
25
26 return <xml><body>
27 <dyn signal={ks <- signal ks;
28 return (List.mapX (fn kr => <xml><div>
29 {[kr.Key]}:
30 <ctextbox source={kr.Nam}/>
31 <ctextbox size={5} source={kr.ShoeSize}/>
32 <button value="Latest" onclick={ro <- rpc (current {Id = kr.Key});
33 case ro of
34 None => alert "Can't get it!"
35 | Some r =>
36 set kr.Nam r.Nam;
37 set kr.ShoeSize (show r.ShoeSize)}/>
38 <button value="Update" onclick={name <- get kr.Nam;
39 shoeSize <- get kr.ShoeSize;
40 rpc (update {Id = kr.Key,
41 Nam = name,
42 ShoeSize = readError shoeSize})
43 }/>
44 </div></xml>) ks)}/>
45
46 <h2>Add one:</h2>
47
48 <table>
49 <tr><th>Id:</th> <td><ctextbox size={5} source={id}/></td></tr>
50 <tr><th>Name:</th> <td><ctextbox source={name}/></td></tr>
51 <tr><th>Shoe size:</th> <td><ctextbox size={5} source={shoeSize}/></td></tr>
52 <tr><th><button value="Add" onclick={id <- get id;
53 name <- get name;
54 shoeSize <- get shoeSize;
55 rpc (insert {Id = readError id, Nam = name,
56 ShoeSize = readError shoeSize});
57
58 cur <- get ks;
59 kr <- expandKey (readError id);
60 set ks (kr :: cur)}/></th></tr>
61 </table>
62 </body></xml>