summaryrefslogtreecommitdiff
path: root/tests/tryRpc.ur
blob: 7a8d3a8b3187fb973fcda2f33a7325ee69283875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
fun isBeppo (s : string) : transaction string =
    case s of
        "Beppo" => return "Yup, that's him!"
      | "Mephisto" => error <xml>Great googely moogely!</xml>
      | _ => return "Who's that?"

fun listOf (n : int) =
    if n < 0 then
        error <xml>Negative!</xml>
    else if n = 0 then
        return []
    else
        ls <- listOf (n - 1);
        return (n :: ls)

fun length ls =
    case ls of
        [] => 0
      | _ :: ls' => 1 + length ls'

fun main () : transaction page =
    s <- source "";
    ns <- source "";
    return <xml><body>
      <ctextbox source={s}/>
      <button value="rpc" onclick={fn _ => v <- get s;
                                      r <- rpc (isBeppo v);
                                      alert r}/>
      <button value="tryRpc" onclick={fn _ => v <- get s;
                                         r <- tryRpc (isBeppo v);
                                         case r of
                                             None => alert "Faaaaaailure."
                                           | Some r => alert ("Success: " ^ r)}/>

      <hr/>

      <ctextbox source={ns}/>
      <button value="rpc" onclick={fn _ => v <- get ns;
                                      r <- rpc (listOf (readError v));
                                      alert (show (length r))}/>
      <button value="tryRpc" onclick={fn _ => v <- get ns;
                                         r <- tryRpc (listOf (readError v));
                                         case r of
                                             None => alert "Faaaaaailure."
                                           | Some r => alert ("Success: " ^ show (length r))}/>
    </body></xml>