adamc@56
|
1 type int
|
adamc@56
|
2 type float
|
adamc@56
|
3 type string
|
adamc@91
|
4
|
adamc@119
|
5 type unit = {}
|
adamc@119
|
6
|
adamc@186
|
7 datatype bool = False | True
|
adamc@186
|
8
|
adamc@91
|
9
|
adamc@203
|
10 (** SQL *)
|
adamc@203
|
11
|
adamc@203
|
12 con sql_table :: {Type} -> Type
|
adamc@203
|
13
|
adamc@204
|
14 (*** Queries *)
|
adamc@204
|
15
|
adamc@204
|
16 con sql_query :: {{Type}} -> Type
|
adamc@229
|
17 con sql_query1 :: {{Type}} -> {{Type}} -> Type
|
adamc@223
|
18 con sql_exp :: {{Type}} -> {{Type}} -> Type -> Type
|
adamc@204
|
19
|
adamc@223
|
20 con sql_subset :: {{Type}} -> {{Type}} -> Type
|
adamc@223
|
21 val sql_subset : keep_drop :: {({Type} * {Type})}
|
adamc@223
|
22 -> sql_subset
|
adamc@223
|
23 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
|
adamc@223
|
24 [nm] ~ acc => fields.1 ~ fields.2 =>
|
adamc@223
|
25 [nm = fields.1 ++ fields.2] ++ acc) [] keep_drop)
|
adamc@223
|
26 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
|
adamc@223
|
27 [nm] ~ acc =>
|
adamc@223
|
28 [nm = fields.1] ++ acc) [] keep_drop)
|
adamc@223
|
29 val sql_subset_all : tables :: {{Type}}
|
adamc@223
|
30 -> sql_subset tables tables
|
adamc@223
|
31
|
adamc@229
|
32 val sql_query1 : tables ::: {{Type}}
|
adamc@224
|
33 -> grouped ::: {{Type}}
|
adamc@223
|
34 -> selected ::: {{Type}}
|
adamc@223
|
35 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc =>
|
adamc@223
|
36 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables),
|
adamc@223
|
37 Where : sql_exp tables [] bool,
|
adamc@224
|
38 GroupBy : sql_subset tables grouped,
|
adamc@224
|
39 Having : sql_exp grouped tables bool,
|
adamc@224
|
40 SelectFields : sql_subset grouped selected}
|
adamc@229
|
41 -> sql_query1 tables selected
|
adamc@229
|
42
|
adamc@229
|
43 type sql_relop
|
adamc@229
|
44 val sql_union : sql_relop
|
adamc@229
|
45 val sql_intersect : sql_relop
|
adamc@229
|
46 val sql_except : sql_relop
|
adamc@229
|
47 val sql_relop : sql_relop
|
adamc@229
|
48 -> tables1 ::: {{Type}}
|
adamc@229
|
49 -> tables2 ::: {{Type}}
|
adamc@229
|
50 -> selected ::: {{Type}}
|
adamc@229
|
51 -> sql_query1 tables1 selected -> sql_query1 tables2 selected -> sql_query1 selected selected
|
adamc@229
|
52
|
adamc@230
|
53 type sql_direction
|
adamc@230
|
54 val sql_asc : sql_direction
|
adamc@230
|
55 val sql_desc : sql_direction
|
adamc@230
|
56
|
adamc@230
|
57 con sql_order_by :: {{Type}} -> Type
|
adamc@230
|
58 val sql_order_by_Nil : tables :: {{Type}} -> sql_order_by tables
|
adamc@230
|
59 val sql_order_by_Cons : tables ::: {{Type}} -> t ::: Type
|
adamc@230
|
60 -> sql_exp tables [] t -> sql_order_by tables
|
adamc@230
|
61 -> sql_order_by tables
|
adamc@230
|
62
|
adamc@229
|
63 val sql_query : tables ::: {{Type}}
|
adamc@229
|
64 -> selected ::: {{Type}}
|
adamc@230
|
65 -> {Rows : sql_query1 tables selected,
|
adamc@230
|
66 OrderBy : sql_order_by tables}
|
adamc@223
|
67 -> sql_query selected
|
adamc@204
|
68
|
adamc@225
|
69 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
|
adamc@221
|
70 -> tab :: Name -> field :: Name
|
adamc@223
|
71 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg fieldType
|
adamc@209
|
72
|
adamc@221
|
73 class sql_injectable
|
adamc@221
|
74 val sql_bool : sql_injectable bool
|
adamc@221
|
75 val sql_int : sql_injectable int
|
adamc@221
|
76 val sql_float : sql_injectable float
|
adamc@221
|
77 val sql_string : sql_injectable string
|
adamc@223
|
78 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> t -> sql_injectable t -> sql_exp tables agg t
|
adamc@209
|
79
|
adamc@220
|
80 con sql_unary :: Type -> Type -> Type
|
adamc@220
|
81 val sql_not : sql_unary bool bool
|
adamc@223
|
82 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg ::: Type -> res ::: Type
|
adamc@223
|
83 -> sql_unary arg res -> sql_exp tables agg arg -> sql_exp tables agg res
|
adamc@220
|
84
|
adamc@220
|
85 con sql_binary :: Type -> Type -> Type -> Type
|
adamc@220
|
86 val sql_and : sql_binary bool bool bool
|
adamc@220
|
87 val sql_or : sql_binary bool bool bool
|
adamc@223
|
88 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
|
adamc@223
|
89 -> sql_binary arg1 arg2 res -> sql_exp tables agg arg1 -> sql_exp tables agg arg2 -> sql_exp tables agg res
|
adamc@220
|
90
|
adamc@219
|
91 type sql_comparison
|
adamc@219
|
92 val sql_eq : sql_comparison
|
adamc@219
|
93 val sql_ne : sql_comparison
|
adamc@219
|
94 val sql_lt : sql_comparison
|
adamc@219
|
95 val sql_le : sql_comparison
|
adamc@219
|
96 val sql_gt : sql_comparison
|
adamc@219
|
97 val sql_ge : sql_comparison
|
adamc@219
|
98 val sql_comparison : sql_comparison
|
adamc@223
|
99 -> tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> sql_exp tables agg t -> sql_exp tables agg t
|
adamc@223
|
100 -> sql_injectable t -> sql_exp tables agg bool
|
adamc@203
|
101
|
adamc@203
|
102 (** XML *)
|
adamc@203
|
103
|
adamc@139
|
104 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
|
adamc@91
|
105
|
adamc@91
|
106
|
adamc@139
|
107 con xml :: {Unit} -> {Type} -> {Type} -> Type
|
adamc@141
|
108 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
|
adamc@104
|
109 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent
|
adamc@139
|
110 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
|
adamc@139
|
111 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner
|
adamc@139
|
112 -> bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner
|
adamc@104
|
113 -> $attrsGiven
|
adamc@139
|
114 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter
|
adamc@139
|
115 -> xml ctxInner useInner bindInner
|
adamc@139
|
116 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
|
adamc@140
|
117 val join : ctx ::: {Unit}
|
adamc@139
|
118 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
|
adamc@139
|
119 -> use1 ~ bind1 -> bind1 ~ bind2
|
adamc@140
|
120 -> xml ctx use1 bind1
|
adamc@140
|
121 -> xml ctx (use1 ++ bind1) bind2
|
adamc@140
|
122 -> xml ctx use1 (bind1 ++ bind2)
|
adamc@148
|
123 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type}
|
adamc@148
|
124 -> use1 ~ use2
|
adamc@148
|
125 -> xml ctx use1 bind
|
adamc@148
|
126 -> xml ctx (use1 ++ use2) bind
|
adamc@91
|
127
|
adamc@110
|
128 con xhtml = xml [Html]
|
adamc@139
|
129 con page = xhtml [] []
|
adamc@110
|
130
|
adamc@204
|
131 (*** HTML details *)
|
adamc@204
|
132
|
adamc@140
|
133 con html = [Html]
|
adamc@140
|
134 con head = [Head]
|
adamc@140
|
135 con body = [Body]
|
adamc@141
|
136 con lform = [Body, LForm]
|
adamc@93
|
137
|
adamc@140
|
138 val head : unit -> tag [] html head [] []
|
adamc@140
|
139 val title : unit -> tag [] head [] [] []
|
adamc@110
|
140
|
adamc@140
|
141 val body : unit -> tag [] html body [] []
|
adamc@140
|
142 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@140
|
143 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
|
adamc@141
|
144 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@141
|
145 -> tag attrs ([Body] ++ ctx) [] [] []
|
adamc@141
|
146
|
adamc@141
|
147 val br : bodyTagStandalone []
|
adamc@119
|
148
|
adamc@140
|
149 val p : bodyTag []
|
adamc@140
|
150 val b : bodyTag []
|
adamc@140
|
151 val i : bodyTag []
|
adamc@140
|
152 val font : bodyTag [Size = int, Face = string]
|
adamc@140
|
153
|
adamc@140
|
154 val h1 : bodyTag []
|
adamc@140
|
155 val li : bodyTag []
|
adamc@140
|
156
|
adamc@140
|
157 val a : bodyTag [Link = page]
|
adamc@140
|
158
|
adamc@141
|
159 val lform : ctx ::: {Unit} -> [Body] ~ ctx -> bind ::: {Type}
|
adamc@141
|
160 -> xml lform [] bind
|
adamc@141
|
161 -> xml ([Body] ++ ctx) [] []
|
adamc@153
|
162 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} =>
|
adamc@141
|
163 ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@141
|
164 -> nm :: Name -> unit
|
adamc@153
|
165 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
|
adamc@153
|
166 val textbox : lformTag string [] []
|
adamc@155
|
167 val password : lformTag string [] []
|
adamc@153
|
168 val ltextarea : lformTag string [] []
|
adamc@153
|
169
|
adamc@190
|
170 val checkbox : lformTag bool [] []
|
adamc@190
|
171
|
adamc@153
|
172 con radio = [Body, Radio]
|
adamc@153
|
173 val radio : lformTag string radio []
|
adamc@153
|
174 val radioOption : unit -> tag [Value = string] radio [] [] []
|
adamc@142
|
175
|
adamc@154
|
176 con select = [Select]
|
adamc@154
|
177 val lselect : lformTag string select []
|
adamc@154
|
178 val loption : unit -> tag [Value = string] select [] [] []
|
adamc@154
|
179
|
adamc@142
|
180 val submit : ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@142
|
181 -> use ::: {Type} -> unit
|
adamc@142
|
182 -> tag [Action = $use -> page] ([LForm] ++ ctx) ([LForm] ++ ctx) use []
|