(* main.sml *) (* main processing *) structure Main :> MAIN = struct open CML (* val print : string -> unit we must mention TextIO somewhere in our program, in order to get the correct version of print *) val print = TextIO.print (* val main : unit -> unit *) fun main() = let val acct : Acct.acct = Acct.make() (* val wait : thread_id -> unit *) fun wait tId = sync(joinEvt tId) (* val sleep : int -> unit *) fun sleep n = sync(timeOutEvt(Time.fromSeconds n)) (* val loop : int * int -> 'a *) fun loop(amount, slp) = select[wrap(alwaysEvt(), fn () => (print "always chosen\n"; sleep slp; loop(amount, slp))), wrap(Acct.decEvt(acct, amount), fn () => (print("decremented " ^ Int.toString amount ^ " from account\n"); sleep slp; loop(amount, slp)))] in loop(10, 2) end (* val doit : unit -> OS.Process.status *) fun doit() = RunCML.doit(main, NONE) end;