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