view tests/tryRpc.ur @ 1907:cb57ba73a61d

make uninstall: Uninstall types_cpp.h, urweb_cpp.h Signed-off-by: Anders Kaseorg <andersk@mit.edu> --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
author Anders Kaseorg <andersk@mit.edu>
date Fri, 22 Nov 2013 09:36:14 -0500
parents e15234fbb163
children
line wrap: on
line source
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>