adamc@590
|
1 fun getOpt (t ::: Type) (o : option t) (v : t) : t =
|
adamc@590
|
2 case o of
|
adamc@590
|
3 None => v
|
adamc@590
|
4 | Some x => x
|
adamc@590
|
5
|
adamc@595
|
6 datatype color = Red | White | Blue
|
adamc@595
|
7
|
adamc@595
|
8 fun colorToString c =
|
adamc@595
|
9 case c of
|
adamc@595
|
10 Red => "R"
|
adamc@595
|
11 | White => "W"
|
adamc@595
|
12 | Blue => "B"
|
adamc@595
|
13
|
adamc@595
|
14 val show_color = mkShow colorToString
|
adamc@595
|
15
|
adamc@591
|
16 cookie int : int
|
adamc@591
|
17 cookie float : float
|
adamc@592
|
18 cookie string : string
|
adamc@592
|
19 cookie bool : bool
|
adamc@593
|
20 cookie pair : int * float
|
adamc@594
|
21 cookie option : option int
|
adamc@595
|
22 cookie color : color
|
adamc@591
|
23
|
adamc@590
|
24 fun main () : transaction page =
|
adamc@590
|
25 n <- getCookie int;
|
adamc@591
|
26 n <- return (getOpt n 7);
|
adamc@591
|
27 sn <- source 6;
|
adamc@591
|
28
|
adamc@591
|
29 f <- getCookie float;
|
adamc@591
|
30 f <- return (getOpt f 1.23);
|
adamc@591
|
31 sf <- source 4.56;
|
adamc@591
|
32
|
adamc@592
|
33 s <- getCookie string;
|
adamc@592
|
34 s <- return (getOpt s "Hi");
|
adamc@592
|
35 ss <- source "Bye";
|
adamc@592
|
36
|
adamc@592
|
37 b <- getCookie bool;
|
adamc@592
|
38 b <- return (getOpt b True);
|
adamc@592
|
39 sb <- source False;
|
adamc@592
|
40
|
adamc@593
|
41 p <- getCookie pair;
|
adamc@593
|
42 p <- return (getOpt p (1, 2.3));
|
adamc@593
|
43 sp <- source (4, 5.6);
|
adamc@593
|
44
|
adamc@594
|
45 o <- getCookie option;
|
adamc@594
|
46 o <- return (getOpt o (Some 1));
|
adamc@595
|
47 so <- source None;
|
adamc@595
|
48
|
adamc@595
|
49 c <- getCookie color;
|
adamc@595
|
50 c <- return (getOpt c White);
|
adamc@595
|
51 sc <- source Blue;
|
adamc@594
|
52
|
adamc@590
|
53 return <xml><body>
|
adamc@590
|
54 <dyn signal={n <- signal sn; return <xml>{[n]}</xml>}/>
|
adamc@591
|
55 <a onclick={set sn n}>CHANGE</a><br/>
|
adamc@591
|
56
|
adamc@591
|
57 <dyn signal={f <- signal sf; return <xml>{[f]}</xml>}/>
|
adamc@591
|
58 <a onclick={set sf f}>CHANGE</a><br/>
|
adamc@592
|
59
|
adamc@592
|
60 <dyn signal={s <- signal ss; return <xml>{[s]}</xml>}/>
|
adamc@592
|
61 <a onclick={set ss s}>CHANGE</a><br/>
|
adamc@592
|
62
|
adamc@592
|
63 <dyn signal={b <- signal sb; return <xml>{[b]}</xml>}/>
|
adamc@592
|
64 <a onclick={set sb b}>CHANGE</a><br/>
|
adamc@593
|
65
|
adamc@593
|
66 <dyn signal={p <- signal sp; return <xml>{[p.1]}, {[p.2]}</xml>}/>
|
adamc@593
|
67 <a onclick={set sp p}>CHANGE</a><br/>
|
adamc@594
|
68
|
adamc@595
|
69 <dyn signal={o <- signal so; case o of
|
adamc@594
|
70 None => return <xml>None</xml>
|
adamc@594
|
71 | Some x => return <xml>{[x]}</xml>}/>
|
adamc@595
|
72 <a onclick={set so o}>CHANGE</a><br/>
|
adamc@595
|
73
|
adamc@595
|
74 <dyn signal={c <- signal sc; return <xml>{[c]}</xml>}/>
|
adamc@595
|
75 <a onclick={set sc c}>CHANGE</a><br/>
|
adamc@590
|
76 </body></xml>
|