Mercurial > urweb
comparison demo/listEdit.ur @ 646:fb2a0e76dcef
ListEdit demo, minus prose
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 10 Mar 2009 12:44:40 -0400 |
parents | |
children | e6bc6bbd7a32 |
comparison
equal
deleted
inserted
replaced
645:1b571a05874c | 646:fb2a0e76dcef |
---|---|
1 datatype rlist = Nil | Cons of {Data : source string, | |
2 NewData : source string, | |
3 Tail : source rlist} | |
4 | |
5 fun showString ss = | |
6 s <- signal ss; | |
7 return <xml>{[s]}</xml> | |
8 | |
9 fun show rls = | |
10 v <- signal rls; | |
11 show' v | |
12 | |
13 and show' rl = | |
14 case rl of | |
15 Nil => return <xml/> | |
16 | Cons {Data = ss, NewData = ss', Tail = rls} => return <xml> | |
17 <dyn signal={showString ss}/> | |
18 <button value="Change to:" onclick={s <- get ss'; set ss s}/> | |
19 <ctextbox source={ss'}/><br/> | |
20 <dyn signal={show rls}/> | |
21 </xml> | |
22 | |
23 fun main () = | |
24 head <- source Nil; | |
25 tailP <- source head; | |
26 data <- source ""; | |
27 | |
28 let | |
29 fun add () = | |
30 data <- get data; | |
31 data <- source data; | |
32 ndata <- source ""; | |
33 tail <- get tailP; | |
34 tail' <- source Nil; | |
35 | |
36 let | |
37 val cons = Cons {Data = data, NewData = ndata, Tail = tail'} | |
38 in | |
39 set tail cons; | |
40 set tailP tail'; | |
41 | |
42 head' <- get head; | |
43 case head' of | |
44 Nil => set head cons | |
45 | _ => return () | |
46 end | |
47 in | |
48 return <xml><body> | |
49 <ctextbox source={data}/> <button value="Add" onclick={add ()}/><br/> | |
50 <br/> | |
51 | |
52 <dyn signal={show head}/> | |
53 </body></xml> | |
54 end |