datatype log = End | Line of string * source log fun render log = case log of End => | Line (line, logS) => {[line]}
and renderS logS = log <- signal logS; return (render log) structure Room = Broadcast(struct type t = string end) sequence s table t : { Id : int, Title : string, Room : Room.topic } fun chat id = r <- oneRow (SELECT t.Title, t.Room FROM t WHERE t.Id = {[id]}); ch <- Room.subscribe r.T.Room; newLine <- source ""; logHead <- source End; logTail <- source logHead; let fun onload () = let fun listener () = s <- recv ch; oldTail <- get logTail; newTail <- source End; set oldTail (Line (s, newTail)); set logTail newTail; listener () in listener () end fun getRoom () = r <- oneRow (SELECT t.Room FROM t WHERE t.Id = {[id]}); return r.T.Room fun speak line = room <- getRoom (); Room.send room line fun doSpeak () = line <- get newLine; set newLine ""; speak line in return

{[r.T.Title]}