diff demo/more/conference.ur @ 1001:1d456a06ea4e

Add tuple pattern-matching at the constructor level
author Adam Chlipala <adamc@hcoop.net>
date Tue, 20 Oct 2009 10:19:00 -0400
parents
children 61c30f0742d7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/more/conference.ur	Tue Oct 20 10:19:00 2009 -0400
@@ -0,0 +1,33 @@
+con reviewMeta = fn (db :: Type, widget :: Type) =>
+                    {Show : db -> xbody,
+                     Widget : nm :: Name -> xml form [] [nm = widget],
+                     WidgetPopulated : nm :: Name -> db -> xml form [] [nm = widget],
+                     Parse : widget -> db,
+                     Inject : sql_injectable db}
+
+fun default [t] (sh : show t) (rd : read t) (inj : sql_injectable t) : reviewMeta (t, string) =
+    {Show = txt,
+     Widget = fn [nm :: Name] => <xml><textbox{nm}/></xml>,
+     WidgetPopulated = fn [nm :: Name] n =>
+                          <xml><textbox{nm} value={show n}/></xml>,
+     Parse = readError,
+     Inject = _}
+
+val int = default
+val float = default
+val string = default
+val bool = {Show = txt,
+            Widget = fn [nm :: Name] => <xml><checkbox{nm}/></xml>,
+            WidgetPopulated = fn [nm :: Name] b =>
+                                 <xml><checkbox{nm} checked={b}/></xml>,
+            Parse = fn x => x,
+            Inject = _}
+
+functor Make(M : sig
+                 con review :: {(Type * Type)}
+                 val review : $(map reviewMeta review)
+             end) = struct
+
+    fun main () = return <xml/>
+
+end