Mercurial > urweb
annotate demo/listFun.ur @ 469:b393c2fc80f8
About to begin optimization of recursive transaction functions
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 06 Nov 2008 17:09:53 -0500 |
parents | e756d3a47726 |
children | 7ef4b2911b09 |
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@400 | 15 Reversed list: {toXml (rev ls)}<br/> |
adamc@399 | 16 Length: {[length ls]}<br/> |
adamc@399 | 17 <br/> |
adamc@398 | 18 |
adamc@398 | 19 <form> |
adamc@398 | 20 Add element: <textbox{#X}/> <submit action={cons ls}/> |
adamc@398 | 21 </form> |
adamc@398 | 22 </body></xml> |
adamc@398 | 23 |
adamc@398 | 24 and cons (ls : list M.t) (r : {X : string}) = |
adamc@398 | 25 case M.fromString r.X of |
adamc@398 | 26 None => return <xml><body>Invalid string!</body></xml> |
adamc@398 | 27 | Some v => console (Cons (v, ls)) |
adamc@398 | 28 |
adamc@398 | 29 fun main () = console Nil |
adamc@386 | 30 end |