comparison lib/basis.urs @ 354:527529a083d9

Basis indents and type-checks with new twiddle syntax
author Adam Chlipala <adamc@hcoop.net>
date Sun, 12 Oct 2008 11:44:43 -0400
parents 58eeeb3cbf40
children 383c72d11db8
comparison
equal deleted inserted replaced
353:9390c55b9f1f 354:527529a083d9
50 con sql_query1 :: {{Type}} -> {{Type}} -> {Type} -> Type 50 con sql_query1 :: {{Type}} -> {{Type}} -> {Type} -> Type
51 con sql_exp :: {{Type}} -> {{Type}} -> {Type} -> Type -> Type 51 con sql_exp :: {{Type}} -> {{Type}} -> {Type} -> Type -> Type
52 52
53 con sql_subset :: {{Type}} -> {{Type}} -> Type 53 con sql_subset :: {{Type}} -> {{Type}} -> Type
54 val sql_subset : keep_drop :: {({Type} * {Type})} 54 val sql_subset : keep_drop :: {({Type} * {Type})}
55 -> sql_subset 55 -> sql_subset
56 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc => 56 (fold (fn nm (fields :: ({Type} * {Type}))
57 [nm] ~ acc => fields.1 ~ fields.2 => 57 acc [[nm] ~ acc]
58 [nm = fields.1 ++ fields.2] ++ acc) [] keep_drop) 58 [fields.1 ~ fields.2] =>
59 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc => 59 [nm = fields.1 ++ fields.2]
60 [nm] ~ acc => 60 ++ acc) [] keep_drop)
61 [nm = fields.1] ++ acc) [] keep_drop) 61 (fold (fn nm (fields :: ({Type} * {Type}))
62 val sql_subset_all : tables :: {{Type}} 62 acc [[nm] ~ acc] =>
63 -> sql_subset tables tables 63 [nm = fields.1] ++ acc)
64 [] keep_drop)
65 val sql_subset_all : tables :: {{Type}} -> sql_subset tables tables
64 66
65 val sql_query1 : tables ::: {{Type}} 67 val sql_query1 : tables ::: {{Type}}
66 -> grouped ::: {{Type}} 68 -> grouped ::: {{Type}}
67 -> selectedFields ::: {{Type}} 69 -> selectedFields ::: {{Type}}
68 -> selectedExps ::: {Type} 70 -> selectedExps ::: {Type}
69 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc => 71 -> {From : $(fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] =>
70 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables), 72 [nm = sql_table fields] ++ acc)
71 Where : sql_exp tables [] [] bool, 73 [] tables),
72 GroupBy : sql_subset tables grouped, 74 Where : sql_exp tables [] [] bool,
73 Having : sql_exp grouped tables [] bool, 75 GroupBy : sql_subset tables grouped,
74 SelectFields : sql_subset grouped selectedFields, 76 Having : sql_exp grouped tables [] bool,
75 SelectExps : $(fold (fn nm => fn t :: Type => fn acc => 77 SelectFields : sql_subset grouped selectedFields,
76 [nm] ~ acc => [nm = sql_exp grouped tables [] t] ++ acc) [] selectedExps) } 78 SelectExps : $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
77 -> sql_query1 tables selectedFields selectedExps 79 [nm = sql_exp grouped tables [] t]
80 ++ acc) [] selectedExps) }
81 -> sql_query1 tables selectedFields selectedExps
78 82
79 type sql_relop 83 type sql_relop
80 val sql_union : sql_relop 84 val sql_union : sql_relop
81 val sql_intersect : sql_relop 85 val sql_intersect : sql_relop
82 val sql_except : sql_relop 86 val sql_except : sql_relop
83 val sql_relop : tables1 ::: {{Type}} 87 val sql_relop : tables1 ::: {{Type}}
84 -> tables2 ::: {{Type}} 88 -> tables2 ::: {{Type}}
85 -> selectedFields ::: {{Type}} 89 -> selectedFields ::: {{Type}}
86 -> selectedExps ::: {Type} 90 -> selectedExps ::: {Type}
87 -> sql_relop 91 -> sql_relop
88 -> sql_query1 tables1 selectedFields selectedExps 92 -> sql_query1 tables1 selectedFields selectedExps
89 -> sql_query1 tables2 selectedFields selectedExps 93 -> sql_query1 tables2 selectedFields selectedExps
90 -> sql_query1 selectedFields selectedFields selectedExps 94 -> sql_query1 selectedFields selectedFields selectedExps
91 95
92 type sql_direction 96 type sql_direction
93 val sql_asc : sql_direction 97 val sql_asc : sql_direction
94 val sql_desc : sql_direction 98 val sql_desc : sql_direction
95 99
96 con sql_order_by :: {{Type}} -> {Type} -> Type 100 con sql_order_by :: {{Type}} -> {Type} -> Type
97 val sql_order_by_Nil : tables ::: {{Type}} -> exps :: {Type} -> sql_order_by tables exps 101 val sql_order_by_Nil : tables ::: {{Type}} -> exps :: {Type} -> sql_order_by tables exps
98 val sql_order_by_Cons : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type 102 val sql_order_by_Cons : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type
99 -> sql_exp tables [] exps t -> sql_direction -> sql_order_by tables exps 103 -> sql_exp tables [] exps t -> sql_direction
100 -> sql_order_by tables exps 104 -> sql_order_by tables exps
105 -> sql_order_by tables exps
101 106
102 type sql_limit 107 type sql_limit
103 val sql_no_limit : sql_limit 108 val sql_no_limit : sql_limit
104 val sql_limit : int -> sql_limit 109 val sql_limit : int -> sql_limit
105 110
106 type sql_offset 111 type sql_offset
107 val sql_no_offset : sql_offset 112 val sql_no_offset : sql_offset
108 val sql_offset : int -> sql_offset 113 val sql_offset : int -> sql_offset
109 114
110 val sql_query : tables ::: {{Type}} 115 val sql_query : tables ::: {{Type}}
111 -> selectedFields ::: {{Type}} 116 -> selectedFields ::: {{Type}}
112 -> selectedExps ::: {Type} 117 -> selectedExps ::: {Type}
113 -> {Rows : sql_query1 tables selectedFields selectedExps, 118 -> {Rows : sql_query1 tables selectedFields selectedExps,
114 OrderBy : sql_order_by tables selectedExps, 119 OrderBy : sql_order_by tables selectedExps,
115 Limit : sql_limit, 120 Limit : sql_limit,
116 Offset : sql_offset} 121 Offset : sql_offset}
117 -> sql_query selectedFields selectedExps 122 -> sql_query selectedFields selectedExps
118 123
119 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}} 124 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type}
120 -> exps ::: {Type} 125 -> fieldType ::: Type -> agg ::: {{Type}}
121 -> tab :: Name -> field :: Name 126 -> exps ::: {Type}
122 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg exps fieldType 127 -> tab :: Name -> field :: Name
123 128 -> sql_exp
124 val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {Type} -> nm :: Name 129 ([tab = [field = fieldType] ++ otherFields] ++ otherTabs)
125 -> sql_exp tabs agg ([nm = t] ++ rest) t 130 agg exps fieldType
131
132 val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {Type}
133 -> nm :: Name
134 -> sql_exp tabs agg ([nm = t] ++ rest) t
126 135
127 class sql_injectable 136 class sql_injectable
128 val sql_bool : sql_injectable bool 137 val sql_bool : sql_injectable bool
129 val sql_int : sql_injectable int 138 val sql_int : sql_injectable int
130 val sql_float : sql_injectable float 139 val sql_float : sql_injectable float
131 val sql_string : sql_injectable string 140 val sql_string : sql_injectable string
132 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type 141 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
133 -> sql_injectable t -> t -> sql_exp tables agg exps t 142 -> t ::: Type
143 -> sql_injectable t -> t -> sql_exp tables agg exps t
134 144
135 con sql_unary :: Type -> Type -> Type 145 con sql_unary :: Type -> Type -> Type
136 val sql_not : sql_unary bool bool 146 val sql_not : sql_unary bool bool
137 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> arg ::: Type -> res ::: Type 147 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
138 -> sql_unary arg res -> sql_exp tables agg exps arg -> sql_exp tables agg exps res 148 -> arg ::: Type -> res ::: Type
149 -> sql_unary arg res -> sql_exp tables agg exps arg
150 -> sql_exp tables agg exps res
139 151
140 con sql_binary :: Type -> Type -> Type -> Type 152 con sql_binary :: Type -> Type -> Type -> Type
141 val sql_and : sql_binary bool bool bool 153 val sql_and : sql_binary bool bool bool
142 val sql_or : sql_binary bool bool bool 154 val sql_or : sql_binary bool bool bool
143 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} 155 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
144 -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type 156 -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
145 -> sql_binary arg1 arg2 res -> sql_exp tables agg exps arg1 -> sql_exp tables agg exps arg2 157 -> sql_binary arg1 arg2 res -> sql_exp tables agg exps arg1
146 -> sql_exp tables agg exps res 158 -> sql_exp tables agg exps arg2
159 -> sql_exp tables agg exps res
147 160
148 type sql_comparison 161 type sql_comparison
149 val sql_eq : sql_comparison 162 val sql_eq : sql_comparison
150 val sql_ne : sql_comparison 163 val sql_ne : sql_comparison
151 val sql_lt : sql_comparison 164 val sql_lt : sql_comparison
157 -> sql_comparison 170 -> sql_comparison
158 -> sql_exp tables agg exps t -> sql_exp tables agg exps t 171 -> sql_exp tables agg exps t -> sql_exp tables agg exps t
159 -> sql_exp tables agg exps bool 172 -> sql_exp tables agg exps bool
160 173
161 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} 174 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
162 -> unit -> sql_exp tables agg exps int 175 -> unit -> sql_exp tables agg exps int
163 176
164 con sql_aggregate :: Type -> Type 177 con sql_aggregate :: Type -> Type
165 val sql_aggregate : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type 178 val sql_aggregate : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
166 -> sql_aggregate t -> sql_exp agg agg exps t -> sql_exp tables agg exps t 179 -> t ::: Type
180 -> sql_aggregate t -> sql_exp agg agg exps t
181 -> sql_exp tables agg exps t
167 182
168 class sql_summable 183 class sql_summable
169 val sql_summable_int : sql_summable int 184 val sql_summable_int : sql_summable int
170 val sql_summable_float : sql_summable float 185 val sql_summable_float : sql_summable float
171 val sql_avg : t ::: Type -> sql_summable t -> sql_aggregate t 186 val sql_avg : t ::: Type -> sql_summable t -> sql_aggregate t
181 196
182 (*** Executing queries *) 197 (*** Executing queries *)
183 198
184 con transaction :: Type -> Type 199 con transaction :: Type -> Type
185 val return : t ::: Type 200 val return : t ::: Type
186 -> t -> transaction t 201 -> t -> transaction t
187 val bind : t1 ::: Type -> t2 ::: Type 202 val bind : t1 ::: Type -> t2 ::: Type
188 -> transaction t1 -> (t1 -> transaction t2) 203 -> transaction t1 -> (t1 -> transaction t2)
189 -> transaction t2 204 -> transaction t2
190 205
191 val query : tables ::: {{Type}} -> exps ::: {Type} -> tables ~ exps 206 val query : tables ::: {{Type}} -> exps ::: {Type}
192 => state ::: Type 207 -> fn [tables ~ exps] =>
193 -> sql_query tables exps 208 state ::: Type
194 -> ($(exps ++ fold (fn nm (fields :: {Type}) acc => [nm] ~ acc => [nm = $fields] ++ acc) [] tables) 209 -> sql_query tables exps
195 -> state 210 -> ($(exps ++ fold (fn nm (fields :: {Type}) [[nm] ~ acc] =>
196 -> transaction state) 211 [nm = $fields] ++ acc) [] tables)
197 -> state 212 -> state
198 -> transaction state 213 -> transaction state)
214 -> state
215 -> transaction state
199 216
200 217
201 (*** Database mutators *) 218 (*** Database mutators *)
202 219
203 type dml 220 type dml
204 val dml : dml -> transaction unit 221 val dml : dml -> transaction unit
205 222
206 val insert : fields ::: {Type} 223 val insert : fields ::: {Type}
207 -> sql_table fields 224 -> sql_table fields
208 -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc => 225 -> $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
209 [nm = sql_exp [] [] [] t] ++ acc) [] fields) 226 [nm = sql_exp [] [] [] t] ++ acc)
210 -> dml 227 [] fields)
211 228 -> dml
212 val update : changed :: {Type} -> unchanged ::: {Type} -> changed ~ unchanged 229
213 => $(fold (fn nm (t :: Type) acc => [nm] ~ acc => 230 val update : changed :: {Type} -> unchanged ::: {Type} ->
214 [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed) 231 fn [changed ~ unchanged] =>
215 -> sql_table (changed ++ unchanged) 232 $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
216 -> sql_exp [T = changed ++ unchanged] [] [] bool 233 [nm = sql_exp [T = changed ++ unchanged] [] [] t]
217 -> dml 234 ++ acc)
235 [] changed)
236 -> sql_table (changed ++ unchanged)
237 -> sql_exp [T = changed ++ unchanged] [] [] bool
238 -> dml
218 239
219 val delete : fields ::: {Type} 240 val delete : fields ::: {Type}
220 -> sql_table fields 241 -> sql_table fields
221 -> sql_exp [T = fields] [] [] bool 242 -> sql_exp [T = fields] [] [] bool
222 -> dml 243 -> dml
223 244
224 (*** Sequences *) 245 (*** Sequences *)
225 246
226 type sql_sequence 247 type sql_sequence
227 val nextval : sql_sequence -> transaction int 248 val nextval : sql_sequence -> transaction int
232 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type 253 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
233 254
234 255
235 con xml :: {Unit} -> {Type} -> {Type} -> Type 256 con xml :: {Unit} -> {Type} -> {Type} -> Type
236 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use [] 257 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
237 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent 258 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type}
238 => ctxOuter ::: {Unit} -> ctxInner ::: {Unit} 259 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
239 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner 260 -> useOuter ::: {Type} -> useInner ::: {Type}
240 => bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner 261 -> bindOuter ::: {Type} -> bindInner ::: {Type}
241 => $attrsGiven 262 -> fn [attrsGiven ~ attrsAbsent]
242 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter 263 [useOuter ~ useInner]
243 -> xml ctxInner useInner bindInner 264 [bindOuter ~ bindInner] =>
244 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner) 265 $attrsGiven
266 -> tag (attrsGiven ++ attrsAbsent)
267 ctxOuter ctxInner useOuter bindOuter
268 -> xml ctxInner useInner bindInner
269 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
245 val join : ctx ::: {Unit} 270 val join : ctx ::: {Unit}
246 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type} 271 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
247 -> use1 ~ bind1 => bind1 ~ bind2 272 -> fn [use1 ~ bind1] [bind1 ~ bind2] =>
248 => xml ctx use1 bind1 273 xml ctx use1 bind1
249 -> xml ctx (use1 ++ bind1) bind2 274 -> xml ctx (use1 ++ bind1) bind2
250 -> xml ctx use1 (bind1 ++ bind2) 275 -> xml ctx use1 (bind1 ++ bind2)
251 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type} 276 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type}
252 -> use1 ~ use2 277 -> bind ::: {Type}
253 => xml ctx use1 bind 278 -> fn [use1 ~ use2] =>
254 -> xml ctx (use1 ++ use2) bind 279 xml ctx use1 bind
280 -> xml ctx (use1 ++ use2) bind
255 281
256 con xhtml = xml [Html] 282 con xhtml = xml [Html]
257 con page = xhtml [] [] 283 con page = xhtml [] []
258 con xbody = xml [Body] [] [] 284 con xbody = xml [Body] [] []
259 con xtr = xml [Body, Tr] [] [] 285 con xtr = xml [Body, Tr] [] []
270 296
271 val head : unit -> tag [] html head [] [] 297 val head : unit -> tag [] html head [] []
272 val title : unit -> tag [] head [] [] [] 298 val title : unit -> tag [] head [] [] []
273 299
274 val body : unit -> tag [] html body [] [] 300 val body : unit -> tag [] html body [] []
275 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx => unit 301 con bodyTag = fn (attrs :: {Type}) =>
276 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] [] 302 ctx ::: {Unit} ->
277 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx => unit 303 fn [[Body] ~ ctx] =>
278 -> tag attrs ([Body] ++ ctx) [] [] [] 304 unit -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
305 con bodyTagStandalone = fn (attrs :: {Type}) =>
306 ctx ::: {Unit}
307 -> fn [[Body] ~ ctx] =>
308 unit -> tag attrs ([Body] ++ ctx) [] [] []
279 309
280 val br : bodyTagStandalone [] 310 val br : bodyTagStandalone []
281 311
282 val p : bodyTag [] 312 val p : bodyTag []
283 val b : bodyTag [] 313 val b : bodyTag []
287 val h1 : bodyTag [] 317 val h1 : bodyTag []
288 val li : bodyTag [] 318 val li : bodyTag []
289 319
290 val a : bodyTag [Link = transaction page] 320 val a : bodyTag [Link = transaction page]
291 321
292 val lform : ctx ::: {Unit} -> [Body] ~ ctx => bind ::: {Type} 322 val lform : ctx ::: {Unit} -> bind ::: {Type}
293 -> xml form [] bind 323 -> fn [[Body] ~ ctx] =>
294 -> xml ([Body] ++ ctx) [] [] 324 xml form [] bind
295 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} => 325 -> xml ([Body] ++ ctx) [] []
296 ctx ::: {Unit} -> [LForm] ~ ctx 326 con lformTag = fn (ty :: Type) (inner :: {Unit}) (attrs :: {Type}) =>
297 => nm :: Name -> unit 327 ctx ::: {Unit}
298 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty] 328 -> fn [[LForm] ~ ctx] =>
329 nm :: Name -> unit
330 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
299 val textbox : lformTag string [] [Value = string] 331 val textbox : lformTag string [] [Value = string]
300 val password : lformTag string [] [] 332 val password : lformTag string [] []
301 val ltextarea : lformTag string [] [] 333 val ltextarea : lformTag string [] []
302 334
303 val checkbox : lformTag bool [] [Checked = bool] 335 val checkbox : lformTag bool [] [Checked = bool]
308 340
309 con select = [Select] 341 con select = [Select]
310 val lselect : lformTag string select [] 342 val lselect : lformTag string select []
311 val loption : unit -> tag [Value = string] select [] [] [] 343 val loption : unit -> tag [Value = string] select [] [] []
312 344
313 val submit : ctx ::: {Unit} -> [LForm] ~ ctx 345 val submit : ctx ::: {Unit} -> use ::: {Type}
314 => use ::: {Type} -> unit 346 -> fn [[LForm] ~ ctx] =>
315 -> tag [Action = $use -> transaction page] ([LForm] ++ ctx) ([LForm] ++ ctx) use [] 347 unit
348 -> tag [Action = $use -> transaction page]
349 ([LForm] ++ ctx) ([LForm] ++ ctx) use []
316 350
317 (*** Tables *) 351 (*** Tables *)
318 352
319 val tabl : unit -> tag [Border = int] [Body] [Body, Table] [] [] 353 val tabl : unit -> tag [Border = int] [Body] [Body, Table] [] []
320 val tr : unit -> tag [] [Body, Table] [Body, Tr] [] [] 354 val tr : unit -> tag [] [Body, Table] [Body, Tr] [] []