From 8b3466d0a9c959d05f396c10cd71c7a889bfc0d9 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 1 Jan 2009 11:26:34 -0500 Subject: Basic datatype reactives --- src/jscomp.sml | 17 ++++++++++++++++- tests/stypes.ur | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/jscomp.sml b/src/jscomp.sml index 5e7a2673..72d5cde5 100644 --- a/src/jscomp.sml +++ b/src/jscomp.sml @@ -182,7 +182,22 @@ fun jsExp mode skip outer = 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 diff --git a/tests/stypes.ur b/tests/stypes.ur index c752234c..6c590843 100644 --- a/tests/stypes.ur +++ b/tests/stypes.ur @@ -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 => Nil + | Cons (h, t) => {[h]} :: {delist t} + fun main () : transaction page = sInt <- source 0; sFloat <- source 1.23; @@ -6,6 +28,9 @@ fun main () : transaction page = sOpt <- source None; sBool <- source True; + sColor <- source White; + sList <- source Nil; + return {[n + 3]}}/> Change
@@ -25,4 +50,12 @@ fun main () : transaction page = {[b]}}/> Yes else return No}/> Change
+ + {[c]}}/> + Red + White + Blue
+ + {[isNil ls]}}/> + Change
-- cgit v1.2.3