adamc@679: datatype log = End | Line of string * source log
adamc@679:
adamc@679: fun render log =
adamc@679: case log of
adamc@679: End =>
adamc@679: | Line (line, logS) => {[line]}
adamc@679:
adamc@679: and renderS logS =
adamc@679: log <- signal logS;
adamc@679: return (render log)
adamc@679:
adamc@682: structure Room = Broadcast(struct
adamc@682: type t = string
adamc@682: end)
adamc@682:
adamc@678: sequence s
adamc@682: table t : { Id : int, Title : string, Room : Room.topic }
adamc@678:
adamc@679: fun chat id =
adamc@682: r <- oneRow (SELECT t.Title, t.Room FROM t WHERE t.Id = {[id]});
adamc@682: ch <- Room.subscribe r.T.Room;
adamc@679:
adamc@679: newLine <- source "";
adamc@679: logHead <- source End;
adamc@679: logTail <- source logHead;
adamc@679:
adamc@679: let
adamc@679: fun onload () =
adamc@679: let
adamc@679: fun listener () =
adamc@679: s <- recv ch;
adamc@679: oldTail <- get logTail;
adamc@679: newTail <- source End;
adamc@679: set oldTail (Line (s, newTail));
adamc@679: set logTail newTail;
adamc@679: listener ()
adamc@679: in
adamc@679: listener ()
adamc@679: end
adamc@679:
adamc@682: fun getRoom () =
adamc@682: r <- oneRow (SELECT t.Room FROM t WHERE t.Id = {[id]});
adamc@682: return r.T.Room
adamc@682:
adamc@679: fun speak line =
adamc@682: room <- getRoom ();
adamc@682: Room.send room line
adamc@679:
adamc@679: fun doSpeak () =
adamc@679: line <- get newLine;
adamc@690: set newLine "";
adamc@679: speak line
adamc@679: in
adamc@679: return
adamc@679:
{[r.T.Title]}
adamc@679:
adamc@679:
adamc@679:
adamc@679:
Messages
adamc@679:
adamc@679:
adamc@679:
adamc@679:
adamc@679: end
adamc@679:
adamc@678: fun list () =
adamc@678: queryX (SELECT * FROM t)
adamc@678: (fn r =>
)
adamc@678:
adamc@678: and delete id =
adamc@678: dml (DELETE FROM t WHERE Id = {[id]});
adamc@678: main ()
adamc@678:
adamc@678: and main () : transaction page =
adamc@678: let
adamc@678: fun create r =
adamc@678: id <- nextval s;
adamc@682: room <- Room.create;
adamc@682: dml (INSERT INTO t (Id, Title, Room) VALUES ({[id]}, {[r.Title]}, {[room]}));
adamc@678: main ()
adamc@678: in
adamc@678: ls <- list ();
adamc@678: return
adamc@678: