comparison tests/jsinj.ur @ 595:02c8ab9f3e8b

Injected an enumeration
author Adam Chlipala <adamc@hcoop.net>
date Thu, 08 Jan 2009 09:57:45 -0500
parents 55829473f6a7
children d1ec54288b1a
comparison
equal deleted inserted replaced
594:55829473f6a7 595:02c8ab9f3e8b
1 fun getOpt (t ::: Type) (o : option t) (v : t) : t = 1 fun getOpt (t ::: Type) (o : option t) (v : t) : t =
2 case o of 2 case o of
3 None => v 3 None => v
4 | Some x => x 4 | Some x => x
5
6 datatype color = Red | White | Blue
7
8 fun colorToString c =
9 case c of
10 Red => "R"
11 | White => "W"
12 | Blue => "B"
13
14 val show_color = mkShow colorToString
5 15
6 cookie int : int 16 cookie int : int
7 cookie float : float 17 cookie float : float
8 cookie string : string 18 cookie string : string
9 cookie bool : bool 19 cookie bool : bool
10 cookie pair : int * float 20 cookie pair : int * float
11 cookie option : option int 21 cookie option : option int
22 cookie color : color
12 23
13 fun main () : transaction page = 24 fun main () : transaction page =
14 n <- getCookie int; 25 n <- getCookie int;
15 n <- return (getOpt n 7); 26 n <- return (getOpt n 7);
16 sn <- source 6; 27 sn <- source 6;
31 p <- return (getOpt p (1, 2.3)); 42 p <- return (getOpt p (1, 2.3));
32 sp <- source (4, 5.6); 43 sp <- source (4, 5.6);
33 44
34 o <- getCookie option; 45 o <- getCookie option;
35 o <- return (getOpt o (Some 1)); 46 o <- return (getOpt o (Some 1));
36 op <- source None; 47 so <- source None;
48
49 c <- getCookie color;
50 c <- return (getOpt c White);
51 sc <- source Blue;
37 52
38 return <xml><body> 53 return <xml><body>
39 <dyn signal={n <- signal sn; return <xml>{[n]}</xml>}/> 54 <dyn signal={n <- signal sn; return <xml>{[n]}</xml>}/>
40 <a onclick={set sn n}>CHANGE</a><br/> 55 <a onclick={set sn n}>CHANGE</a><br/>
41 56
49 <a onclick={set sb b}>CHANGE</a><br/> 64 <a onclick={set sb b}>CHANGE</a><br/>
50 65
51 <dyn signal={p <- signal sp; return <xml>{[p.1]}, {[p.2]}</xml>}/> 66 <dyn signal={p <- signal sp; return <xml>{[p.1]}, {[p.2]}</xml>}/>
52 <a onclick={set sp p}>CHANGE</a><br/> 67 <a onclick={set sp p}>CHANGE</a><br/>
53 68
54 <dyn signal={o <- signal op; case o of 69 <dyn signal={o <- signal so; case o of
55 None => return <xml>None</xml> 70 None => return <xml>None</xml>
56 | Some x => return <xml>{[x]}</xml>}/> 71 | Some x => return <xml>{[x]}</xml>}/>
57 <a onclick={set op o}>CHANGE</a><br/> 72 <a onclick={set so o}>CHANGE</a><br/>
73
74 <dyn signal={c <- signal sc; return <xml>{[c]}</xml>}/>
75 <a onclick={set sc c}>CHANGE</a><br/>
58 </body></xml> 76 </body></xml>