annotate tests/jscomp.ur @ 2123:1218daa14279

Document new infix operators
author Adam Chlipala <adam@chlipala.net>
date Thu, 05 Mar 2015 14:58:34 -0500
parents 8fe576c0bee9
children
rev   line source
adamc@973 1 fun fst [a] [b] (x : a) (y : b) = x
adamc@973 2 fun snd [a] [b] (x : a) (y : b) = y
adamc@973 3
adamc@974 4 fun fact n =
adamc@974 5 case n of
adamc@974 6 0 => 1
adamc@974 7 | _ => n * fact (n - 1)
adamc@974 8
adamc@975 9 datatype t =
adamc@975 10 A
adamc@975 11 | B of {C : int, D : float}
adamc@975 12 | E of t * t
adamc@975 13
adamc@975 14 fun render x =
adamc@975 15 case x of
adamc@975 16 A => "A"
adamc@975 17 | B {C = n1, D = n2} => "B(" ^ show n1 ^ "," ^ show n2 ^ ")"
adamc@975 18 | E (x, y) => "C(" ^ render x ^ "," ^ render y ^ ")"
adamc@975 19
adamc@971 20 fun main () =
adamc@971 21 s <- source "";
adamc@973 22 s' <- source "";
adamc@973 23 f <- source (plus 1);
adamc@973 24 f2 <- source fst;
adamc@973 25 r <- source {A = "x", B = "y"};
adamc@975 26 t <- source (E (A, B {C = 10, D = 1.23}));
adamc@975 27 ht <- source <xml>Nothing here yet.</xml>;
adamc@971 28
adamc@971 29 return <xml><body>
adamc@973 30 <ctextbox source={s}/> <ctextbox source={s'}/><br/><br/>
adamc@972 31
adamc@972 32 Function: <button value="+1" onclick={set f (plus 1)}/>
adamc@972 33 <button value="*3" onclick={set f (times 3)}/><br/><br/>
adamc@971 34
adamc@973 35 Function2: <button value="Fst" onclick={set f2 fst}/>
adamc@973 36 <button value="Snd" onclick={set f2 snd}/><br/><br/>
adamc@973 37
adamc@975 38 Both: <button value="*3,Snd" onclick={set f (times 3); set f2 snd}/><br/><br/>
adamc@975 39
adamc@971 40 <button value="Echo" onclick={s <- get s; alert s}/>
adamc@975 41 <button value="Echo2" onclick={s <- get s; alert s; alert s}/>
adamc@973 42 <button value="-" onclick={s <- get s; alert (show (-(readError s : int)))}/>
adamc@971 43 <button value="+1" onclick={s <- get s; alert (show (readError s + 1))}/>
adamc@971 44 <button value="*3" onclick={s <- get s; alert (show ((readError s) * 3))}/>
adamc@974 45 <button value="!" onclick={s <- get s; alert (show (fact (readError s)))}/>
adamc@974 46 <button value="f" onclick={s <- get s; f <- get f; alert (show (f (readError s)))}/>
adamc@974 47 <button value="+1P" onclick={s <- get s; case read s of
adamc@974 48 None => alert "Nada!"
adamc@974 49 | Some (n : int) => alert (show (n + 1))}/>
adamc@973 50
adamc@973 51 <button value="f2" onclick={s <- get s; s' <- get s'; f2 <- get f2; alert (f2 s s')}/><br/><br/>
adamc@973 52
adamc@973 53 <button value="A" onclick={r <- get r; alert r.A}/>
adamc@975 54 <button value="B" onclick={r <- get r; alert r.B}/><br/><br/>
adamc@975 55
adamc@975 56 <button value="render" onclick={t <- get t; alert (render t)}/><br/><br/>
adamc@975 57
adamc@975 58 <dyn signal={signal ht}/>
adamc@975 59 <button value="Set" onclick={s <- get s;
adamc@975 60 set ht <xml><button value="Dynamic!" onclick={alert s}/></xml>}/>
adamc@971 61 </body></xml>