view demo/listFun.ur @ 2190:22117edf8fd3

After a tricky debugging session, limit visibility of type-class instances from anonymous modules
author Adam Chlipala <>
date Sun, 01 Nov 2015 16:33:14 -0500
parents 7ef4b2911b09
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) =
            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))
            return <xml><body>
              Current list: {toXml ls}<br/>
              Reversed list: {toXml (rev ls)}<br/>
              Length: {[length ls]}<br/>

                Add element: <textbox{#X}/> <submit action={cons}/>

    fun main () = console Nil