Mercurial > urweb
comparison demo/noisy.ur @ 651:bab524996fca
Noisy demo
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 10 Mar 2009 17:29:03 -0400 |
parents | |
children | 1a317a707d71 |
comparison
equal
deleted
inserted
replaced
650:fcf0bd3d1667 | 651:bab524996fca |
---|---|
1 datatype list t = Nil | Cons of t * list t | |
2 | |
3 table t : { Id : int, A : string } | |
4 | |
5 fun add id s = | |
6 dml (INSERT INTO t (Id, A) VALUES ({[id]}, {[s]})) | |
7 | |
8 fun del id = | |
9 dml (DELETE FROM t WHERE t.Id = {[id]}) | |
10 | |
11 fun lookup id = | |
12 ro <- oneOrNoRows (SELECT t.A FROM t WHERE t.Id = {[id]}); | |
13 case ro of | |
14 None => return None | |
15 | Some r => return (Some r.T.A) | |
16 | |
17 fun check ls = | |
18 case ls of | |
19 Nil => return () | |
20 | Cons (id, ls') => | |
21 ao <- lookup id; | |
22 alert (case ao of | |
23 None => "Nada" | |
24 | Some a => a); | |
25 check ls' | |
26 | |
27 fun main () = | |
28 idAdd <- source ""; | |
29 aAdd <- source ""; | |
30 | |
31 idDel <- source ""; | |
32 | |
33 return <xml><body> | |
34 <button value="Check values of 1, 2, and 3" onclick={check (Cons (1, Cons (2, Cons (3, Nil))))}/><br/> | |
35 <br/> | |
36 <button value="Add" onclick={id <- get idAdd; a <- get aAdd; add (readError id) a}/> | |
37 <ctextbox source={idAdd}/> | |
38 <ctextbox source={aAdd}/><br/> | |
39 <br/> | |
40 <button value="Delete" onclick={id <- get idDel; del (readError id)}/> | |
41 <ctextbox source={idDel}/> | |
42 </body></xml> |