annotate demo/listFun.ur @ 399:2d64457eedb1

listFun uses length
author Adam Chlipala <adamc@hcoop.net>
date Tue, 21 Oct 2008 13:41:03 -0400
parents ab3177746c78
children e756d3a47726
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@399 15 Length: {[length ls]}<br/>
adamc@399 16 <br/>
adamc@398 17
adamc@398 18 <form>
adamc@398 19 Add element: <textbox{#X}/> <submit action={cons ls}/>
adamc@398 20 </form>
adamc@398 21 </body></xml>
adamc@398 22
adamc@398 23 and cons (ls : list M.t) (r : {X : string}) =
adamc@398 24 case M.fromString r.X of
adamc@398 25 None => return <xml><body>Invalid string!</body></xml>
adamc@398 26 | Some v => console (Cons (v, ls))
adamc@398 27
adamc@398 28 fun main () = console Nil
adamc@386 29 end