adamc@590: fun getOpt (t ::: Type) (o : option t) (v : t) : t = adamc@590: case o of adamc@590: None => v adamc@590: | Some x => x adamc@590: adamc@595: datatype color = Red | White | Blue adamc@595: adamc@595: fun colorToString c = adamc@595: case c of adamc@595: Red => "R" adamc@595: | White => "W" adamc@595: | Blue => "B" adamc@595: adamc@595: val show_color = mkShow colorToString adamc@595: adamc@596: datatype list a = Nil | Cons of a * list a adamc@596: adamc@596: fun delist ls : xbody = adamc@596: case ls of adamc@596: Nil => <xml>Nil</xml> adamc@596: | Cons (h, t) => <xml>{cdata h} :: {delist t}</xml> adamc@596: adamc@597: datatype weird = Foo | Bar | Baz of string adamc@597: adamc@597: fun weirdToString w = adamc@597: case w of adamc@597: Foo => "Foo" adamc@597: | Bar => "Bar" adamc@597: | Baz s => s adamc@597: adamc@597: val show_weird = mkShow weirdToString adamc@597: adamc@591: cookie int : int adamc@591: cookie float : float adamc@592: cookie string : string adamc@592: cookie bool : bool adamc@593: cookie pair : int * float adamc@594: cookie option : option int adamc@595: cookie color : color adamc@596: cookie list : list string adamc@597: cookie weird : weird adamc@591: adamc@590: fun main () : transaction page = adamc@590: n <- getCookie int; adamc@591: n <- return (getOpt n 7); adamc@591: sn <- source 6; adamc@591: adamc@591: f <- getCookie float; adamc@591: f <- return (getOpt f 1.23); adamc@591: sf <- source 4.56; adamc@591: adamc@592: s <- getCookie string; adamc@592: s <- return (getOpt s "Hi"); adamc@592: ss <- source "Bye"; adamc@592: adamc@592: b <- getCookie bool; adamc@592: b <- return (getOpt b True); adamc@592: sb <- source False; adamc@592: adamc@593: p <- getCookie pair; adamc@593: p <- return (getOpt p (1, 2.3)); adamc@593: sp <- source (4, 5.6); adamc@593: adamc@594: o <- getCookie option; adamc@594: o <- return (getOpt o (Some 1)); adamc@595: so <- source None; adamc@595: adamc@595: c <- getCookie color; adamc@595: c <- return (getOpt c White); adamc@595: sc <- source Blue; adamc@594: adamc@596: l <- getCookie list; adamc@596: l <- return (getOpt l (Cons ("A", Cons ("B", Nil)))); adamc@596: sl <- source Nil; adamc@596: adamc@597: w <- getCookie weird; adamc@597: w <- return (getOpt w (Baz "TADA!")); adamc@597: sw <- source Foo; adamc@597: adamc@590: return <xml><body> adamc@590: <dyn signal={n <- signal sn; return <xml>{[n]}</xml>}/> adamc@591: <a onclick={set sn n}>CHANGE</a><br/> adamc@591: adamc@591: <dyn signal={f <- signal sf; return <xml>{[f]}</xml>}/> adamc@591: <a onclick={set sf f}>CHANGE</a><br/> adamc@592: adamc@592: <dyn signal={s <- signal ss; return <xml>{[s]}</xml>}/> adamc@592: <a onclick={set ss s}>CHANGE</a><br/> adamc@592: adamc@592: <dyn signal={b <- signal sb; return <xml>{[b]}</xml>}/> adamc@592: <a onclick={set sb b}>CHANGE</a><br/> adamc@593: adamc@593: <dyn signal={p <- signal sp; return <xml>{[p.1]}, {[p.2]}</xml>}/> adamc@593: <a onclick={set sp p}>CHANGE</a><br/> adamc@594: adamc@595: <dyn signal={o <- signal so; case o of adamc@594: None => return <xml>None</xml> adamc@594: | Some x => return <xml>{[x]}</xml>}/> adamc@595: <a onclick={set so o}>CHANGE</a><br/> adamc@595: adamc@595: <dyn signal={c <- signal sc; return <xml>{[c]}</xml>}/> adamc@595: <a onclick={set sc c}>CHANGE</a><br/> adamc@596: adamc@596: <dyn signal={l <- signal sl; return <xml>{delist l}</xml>}/> adamc@596: <a onclick={set sl l}>CHANGE</a><br/> adamc@597: adamc@597: <dyn signal={w <- signal sw; return <xml>{[w]}</xml>}/> adamc@597: <a onclick={set sw w}>CHANGE</a><br/> adamc@590: </body></xml>