Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
397:4d519baf357c | 398:ab3177746c78 |
---|---|
1 open List | |
2 | |
1 functor Make(M : sig | 3 functor Make(M : sig |
2 type t | 4 type t |
5 val toString : t -> string | |
6 val fromString : string -> option t | |
3 end) = struct | 7 end) = struct |
4 fun main () = return <xml/> | 8 fun toXml (ls : list M.t) = |
9 case ls of | |
10 Nil => <xml>[]</xml> | |
11 | Cons (x, ls') => <xml>{[M.toString x]} :: {toXml ls'}</xml> | |
12 | |
13 fun console (ls : list M.t) = return <xml><body> | |
14 Current list: {toXml ls}<br/> | |
15 | |
16 <form> | |
17 Add element: <textbox{#X}/> <submit action={cons ls}/> | |
18 </form> | |
19 </body></xml> | |
20 | |
21 and cons (ls : list M.t) (r : {X : string}) = | |
22 case M.fromString r.X of | |
23 None => return <xml><body>Invalid string!</body></xml> | |
24 | Some v => console (Cons (v, ls)) | |
25 | |
26 fun main () = console Nil | |
5 end | 27 end |