Mercurial > urweb
comparison tests/rpcDE.ur @ 638:3ee6bb48f6e8
RPC returning an enumeration
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 08 Mar 2009 12:37:42 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
637:24fd1edfcaa3 | 638:3ee6bb48f6e8 |
---|---|
1 datatype result = Neg | Zero | Pos | |
2 | |
3 table t : {A : int} | |
4 | |
5 fun main () : transaction page = | |
6 let | |
7 fun check () = | |
8 r <- oneRow (SELECT SUM(t.A) AS X FROM t); | |
9 return (if r.X < 0 then | |
10 Neg | |
11 else if r.X = 0 then | |
12 Zero | |
13 else | |
14 Pos) | |
15 | |
16 fun show r = | |
17 case r of | |
18 Neg => <xml>-</xml> | |
19 | Zero => <xml>0</xml> | |
20 | Pos => <xml>+</xml> | |
21 in | |
22 s <- source Zero; | |
23 return <xml><body> | |
24 <button value="Get It On!" | |
25 onclick={r <- check (); | |
26 set s r}/><br/> | |
27 <br/> | |
28 Current: <dyn signal={r <- signal s; return (show r)}/> | |
29 </body></xml> | |
30 end |