diff demo/listFun.ur @ 398:ab3177746c78

Simple listShop working
author Adam Chlipala <adamc@hcoop.net>
date Tue, 21 Oct 2008 13:24:54 -0400
parents 4d519baf357c
children 2d64457eedb1
line wrap: on
line diff
--- a/demo/listFun.ur	Tue Oct 21 12:06:35 2008 -0400
+++ b/demo/listFun.ur	Tue Oct 21 13:24:54 2008 -0400
@@ -1,5 +1,27 @@
+open List
+
 functor Make(M : sig
                  type t
+                 val toString : t -> string
+                 val fromString : string -> option t
              end) = struct
-    fun main () = return <xml/>
+    fun toXml (ls : list M.t) =
+        case ls of
+            Nil => <xml>[]</xml>
+          | Cons (x, ls') => <xml>{[M.toString x]} :: {toXml ls'}</xml>
+      
+    fun console (ls : list M.t) = return <xml><body>
+      Current list: {toXml ls}<br/>
+
+      <form>
+        Add element: <textbox{#X}/> <submit action={cons ls}/>
+      </form>
+    </body></xml>
+
+    and cons (ls : list M.t) (r : {X : string}) =
+        case M.fromString r.X of
+            None => return <xml><body>Invalid string!</body></xml>
+          | Some v => console (Cons (v, ls))
+
+    fun main () = console Nil
 end