Mercurial > urweb
comparison tests/crud.ur @ 329:eec65c11d3e2
foldTR2
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 13 Sep 2008 10:30:45 -0400 |
parents | 3a57f3b3a3f8 |
children | 02d15d81ae9b |
comparison
equal
deleted
inserted
replaced
328:58f1260f293f | 329:eec65c11d3e2 |
---|---|
1 con colMeta = fn cols :: {Type} => $(Top.mapTT (fn t => {Show : t -> xbody}) cols) | 1 con colMeta' = fn t :: Type => {Show : t -> xbody} |
2 con colMeta = fn cols :: {Type} => $(Top.mapTT colMeta' cols) | |
2 | 3 |
3 functor Make(M : sig | 4 functor Make(M : sig |
4 con cols :: {Type} | 5 con cols :: {Type} |
5 constraint [Id] ~ cols | 6 constraint [Id] ~ cols |
6 val tab : sql_table ([Id = int] ++ cols) | 7 val tab : sql_table ([Id = int] ++ cols) |
13 open constraints M | 14 open constraints M |
14 val tab = M.tab | 15 val tab = M.tab |
15 | 16 |
16 fun list () = | 17 fun list () = |
17 rows <- query (SELECT * FROM tab AS T) | 18 rows <- query (SELECT * FROM tab AS T) |
18 (fn fs acc => return <body> | 19 (fn (fs : {T : $([Id = int] ++ M.cols)}) acc => return <body> |
19 {acc} | 20 {acc} |
20 <tr> | 21 <tr> |
21 <td>{txt _ fs.T.Id}</td> | 22 <td>{txt _ fs.T.Id}</td> |
22 {fold [fn cols :: {Type} => $cols -> colMeta cols -> xtr] | 23 {foldTR2 [idT] [colMeta'] [fn _ => xtr] |
23 (fn (nm :: Name) (t :: Type) (rest :: {Type}) acc => | 24 (fn (nm :: Name) (t :: Type) (rest :: {Type}) => |
24 [[nm] ~ rest] => | 25 [[nm] ~ rest] => |
25 fn r cols => | 26 fn v funcs acc => |
26 <tr> | 27 <tr> |
27 <td>{cols.nm.Show r.nm}</td> | 28 <td>{funcs.Show v}</td> |
28 {acc (r -- nm) (cols -- nm)} | 29 {acc} |
29 </tr>) | 30 </tr>) |
30 (fn _ _ => <tr></tr>) | 31 <tr></tr> |
31 [M.cols] (fs.T -- #Id) M.cols} | 32 [M.cols] (fs.T -- #Id) M.cols} |
32 </tr> | 33 </tr> |
33 </body>) <body></body>; | 34 </body>) <body></body>; |
34 return <html><head> | 35 return <html><head> |
35 <title>List</title> | 36 <title>List</title> |