view demo/listFun.ur @ 1650:1bfd793e7eb8

Add dynamic content before running its scripts, to get IDs in scope; fix generation of Postgres queries with blobs
author Adam Chlipala <adam@chlipala.net>
date Thu, 29 Dec 2011 16:08:34 -0500
parents 7ef4b2911b09
children
line wrap: on
line source
open List

functor Make(M : sig
                 type t
                 val toString : t -> string
                 val fromString : string -> option t
             end) = struct
    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) =
        let
            fun cons (r : {X : string}) =
                case M.fromString r.X of
                    None => return <xml><body>Invalid string!</body></xml>
                  | Some v => console (Cons (v, ls))
        in
            return <xml><body>
              Current list: {toXml ls}<br/>
              Reversed list: {toXml (rev ls)}<br/>
              Length: {[length ls]}<br/>
              <br/>

              <form>
                Add element: <textbox{#X}/> <submit action={cons}/>
              </form>
            </body></xml>
        end

    fun main () = console Nil
end