structure Room = Broadcast.Make(struct type t = string end) sequence s table t : { Id : int, Title : string, Room : Room.topic } PRIMARY KEY Id fun chat id () = r <- oneRow (SELECT t.Title, t.Room FROM t WHERE t.Id = {[id]}); ch <- Room.subscribe r.T.Room; newLine <- source ""; buf <- Buffer.create; let fun onload () = let fun listener () = s <- recv ch; Buffer.write buf s; 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 ""; rpc (speak line) in return

{[r.T.Title]}