Mercurial > urweb
changeset 588:5803b4f041cb
Basic datatype reactives
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 01 Jan 2009 11:26:34 -0500 |
parents | 4c899701bd28 |
children | 102e81d975e3 |
files | src/jscomp.sml tests/stypes.ur |
diffstat | 2 files changed, 49 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jscomp.sml Thu Jan 01 11:16:57 2009 -0500 +++ b/src/jscomp.sml Thu Jan 01 11:26:34 2009 -0500 @@ -182,7 +182,22 @@ str ":", succ, str ")"] - | PCon _ => raise Fail "PCon" + | PCon (_, pc, NONE) => + strcat [str ("(d" ^ Int.toString depth ^ "=="), + patCon pc, + str "?", + succ, + str ":", + fail, + str ")"] + | PCon (_, pc, SOME p) => + strcat [str ("(d" ^ Int.toString depth ^ ".n=="), + patCon pc, + str ("?(d" ^ Int.toString depth ^ "=d" ^ Int.toString depth ^ ".v,"), + succ, + str "):", + fail, + str ")"] | PRecord xps => let val (_, succ) = foldl
--- a/tests/stypes.ur Thu Jan 01 11:16:57 2009 -0500 +++ b/tests/stypes.ur Thu Jan 01 11:26:34 2009 -0500 @@ -1,3 +1,25 @@ +datatype color = Red | White | Blue + +fun c2s c = + case c of + Red => "Red" + | White => "White" + | Blue => "Blue" + +val show_color = mkShow c2s + +datatype list a = Nil | Cons of a * list a + +fun isNil (t ::: Type) (ls : list t) = + case ls of + Nil => True + | _ => False + +fun delist (ls : list string) : xml body [] [] = + case ls of + Nil => <xml>Nil</xml> + | Cons (h, t) => <xml>{[h]} :: {delist t}</xml> + fun main () : transaction page = sInt <- source 0; sFloat <- source 1.23; @@ -6,6 +28,9 @@ sOpt <- source None; sBool <- source True; + sColor <- source White; + sList <- source Nil; + return <xml><body> <dyn signal={n <- signal sInt; return <xml>{[n + 3]}</xml>}/> <a onclick={set sInt 1}>Change</a><br/> @@ -25,4 +50,12 @@ <dyn signal={b <- signal sBool; return <xml>{[b]}</xml>}/> <dyn signal={b <- signal sBool; if b then return <xml>Yes</xml> else return <xml>No</xml>}/> <a onclick={set sBool False}>Change</a><br/> + + <dyn signal={c <- signal sColor; return <xml>{[c]}</xml>}/> + <a onclick={set sColor Red}>Red</a> + <a onclick={set sColor White}>White</a> + <a onclick={set sColor Blue}>Blue</a><br/> + + <dyn signal={ls <- signal sList; return <xml>{[isNil ls]}</xml>}/> + <a onclick={set sList (Cons ("A", Cons ("B", Nil)))}>Change</a><br/> </body></xml>