summaryrefslogtreecommitdiff
path: root/tests/tryRpc.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
commita2386e85bac4e7da8fa1f29a676941b592d35a5d (patch)
tree2dba7c473ff3a8063145c3cd8506ac9013faa904 /tests/tryRpc.ur
parent831f3ff6a5ea8fe1e727be1d9f63a2e823072457 (diff)
Basis.tryRpc
Diffstat (limited to 'tests/tryRpc.ur')
-rw-r--r--tests/tryRpc.ur46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/tryRpc.ur b/tests/tryRpc.ur
new file mode 100644
index 00000000..7a8d3a8b
--- /dev/null
+++ b/tests/tryRpc.ur
@@ -0,0 +1,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>