comparison tests/rpcO.ur @ 641:b98f547a6a45

RPC returning an option
author Adam Chlipala <adamc@hcoop.net>
date Sun, 08 Mar 2009 13:41:55 -0400
parents
children
comparison
equal deleted inserted replaced
640:63b0bcacd535 641:b98f547a6a45
1 table t : {A : int}
2
3 fun main () : transaction page =
4 let
5 fun check () =
6 r <- oneRow (SELECT SUM(t.A) AS X FROM t);
7 return (if r.X < 0 then
8 (Some 3, None)
9 else
10 (None, Some "Hi"))
11
12 fun show (t ::: Type) (_ : show t) (opt : option t) =
13 case opt of
14 None => <xml>None</xml>
15 | Some v => <xml>{[v]}</xml>
16 in
17 s <- source (None, None);
18 return <xml><body>
19 <button value="Get It On!"
20 onclick={r <- check ();
21 set s r}/><br/>
22 <br/>
23 Current: <dyn signal={p <- signal s; return <xml>{show p.1}, {show p.2}</xml>}/>
24 </body></xml>
25 end