Mercurial > urweb
comparison tests/tryRpc.ur @ 1848:e15234fbb163
Basis.tryRpc
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Tue, 16 Apr 2013 10:55:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1847:8958b580d026 | 1848:e15234fbb163 |
---|---|
1 fun isBeppo (s : string) : transaction string = | |
2 case s of | |
3 "Beppo" => return "Yup, that's him!" | |
4 | "Mephisto" => error <xml>Great googely moogely!</xml> | |
5 | _ => return "Who's that?" | |
6 | |
7 fun listOf (n : int) = | |
8 if n < 0 then | |
9 error <xml>Negative!</xml> | |
10 else if n = 0 then | |
11 return [] | |
12 else | |
13 ls <- listOf (n - 1); | |
14 return (n :: ls) | |
15 | |
16 fun length ls = | |
17 case ls of | |
18 [] => 0 | |
19 | _ :: ls' => 1 + length ls' | |
20 | |
21 fun main () : transaction page = | |
22 s <- source ""; | |
23 ns <- source ""; | |
24 return <xml><body> | |
25 <ctextbox source={s}/> | |
26 <button value="rpc" onclick={fn _ => v <- get s; | |
27 r <- rpc (isBeppo v); | |
28 alert r}/> | |
29 <button value="tryRpc" onclick={fn _ => v <- get s; | |
30 r <- tryRpc (isBeppo v); | |
31 case r of | |
32 None => alert "Faaaaaailure." | |
33 | Some r => alert ("Success: " ^ r)}/> | |
34 | |
35 <hr/> | |
36 | |
37 <ctextbox source={ns}/> | |
38 <button value="rpc" onclick={fn _ => v <- get ns; | |
39 r <- rpc (listOf (readError v)); | |
40 alert (show (length r))}/> | |
41 <button value="tryRpc" onclick={fn _ => v <- get ns; | |
42 r <- tryRpc (listOf (readError v)); | |
43 case r of | |
44 None => alert "Faaaaaailure." | |
45 | Some r => alert ("Success: " ^ show (length r))}/> | |
46 </body></xml> |