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]}
Messages
end
fun list () =
queryX (SELECT * FROM t)
(fn r =>
)
and delete id =
dml (DELETE FROM t WHERE Id = {[id]});
main ()
and main () : transaction page =
let
fun create r =
id <- nextval s;
room <- Room.create;
dml (INSERT INTO t (Id, Title, Room) VALUES ({[id]}, {[r.Title]}, {[room]}));
main ()
in
ls <- list ();
return