annotate lib/basis.urs @ 441:c5335613f31e

CURRENT_TIMESTAMP
author Adam Chlipala <adamc@hcoop.net>
date Thu, 30 Oct 2008 15:33:28 -0400
parents 1a4c1b5f4d8f
children bd9ee9aeca2f
rev   line source
adamc@56 1 type int
adamc@56 2 type float
adamc@56 3 type string
adamc@436 4 type time
adamc@91 5
adamc@119 6 type unit = {}
adamc@119 7
adamc@186 8 datatype bool = False | True
adamc@186 9
adamc@288 10 datatype option t = None | Some of t
adamc@284 11
adamc@91 12
adamc@256 13 (** Basic type classes *)
adamc@256 14
adamc@256 15 class eq
adamc@256 16 val eq : t ::: Type -> eq t -> t -> t -> bool
adamc@257 17 val ne : t ::: Type -> eq t -> t -> t -> bool
adamc@256 18 val eq_int : eq int
adamc@394 19 val eq_float : eq float
adamc@256 20 val eq_string : eq string
adamc@256 21 val eq_bool : eq bool
adamc@437 22 val eq_time : eq time
adamc@422 23 val mkEq : t ::: Type -> (t -> t -> bool) -> eq t
adamc@256 24
adamc@389 25 class num
adamc@417 26 val zero : t ::: Type -> num t -> t
adamc@389 27 val neg : t ::: Type -> num t -> t -> t
adamc@389 28 val plus : t ::: Type -> num t -> t -> t -> t
adamc@389 29 val minus : t ::: Type -> num t -> t -> t -> t
adamc@389 30 val times : t ::: Type -> num t -> t -> t -> t
adamc@389 31 val div : t ::: Type -> num t -> t -> t -> t
adamc@389 32 val mod : t ::: Type -> num t -> t -> t -> t
adamc@389 33 val num_int : num int
adamc@390 34 val num_float : num float
adamc@389 35
adamc@391 36 class ord
adamc@391 37 val lt : t ::: Type -> ord t -> t -> t -> bool
adamc@391 38 val le : t ::: Type -> ord t -> t -> t -> bool
adamc@391 39 val gt : t ::: Type -> ord t -> t -> t -> bool
adamc@391 40 val ge : t ::: Type -> ord t -> t -> t -> bool
adamc@391 41 val ord_int : ord int
adamc@394 42 val ord_float : ord float
adamc@394 43 val ord_string : ord string
adamc@394 44 val ord_bool : ord bool
adamc@437 45 val ord_time : ord time
adamc@391 46
adamc@256 47
adamc@283 48 (** String operations *)
adamc@283 49
adamc@283 50 val strcat : string -> string -> string
adamc@283 51
adamc@286 52 class show
adamc@286 53 val show : t ::: Type -> show t -> t -> string
adamc@286 54 val show_int : show int
adamc@286 55 val show_float : show float
adamc@286 56 val show_string : show string
adamc@286 57 val show_bool : show bool
adamc@436 58 val show_time : show time
adamc@286 59
adamc@290 60 class read
adamc@290 61 val read : t ::: Type -> read t -> string -> option t
adamc@292 62 val readError : t ::: Type -> read t -> string -> t
adamc@292 63 (* [readError] calls [error] if the input is malformed. *)
adamc@290 64 val read_int : read int
adamc@290 65 val read_float : read float
adamc@290 66 val read_string : read string
adamc@290 67 val read_bool : read bool
adamc@436 68 val read_time : read time
adamc@288 69
adamc@283 70
adamc@203 71 (** SQL *)
adamc@203 72
adamc@203 73 con sql_table :: {Type} -> Type
adamc@203 74
adamc@204 75 (*** Queries *)
adamc@204 76
adamc@233 77 con sql_query :: {{Type}} -> {Type} -> Type
adamc@233 78 con sql_query1 :: {{Type}} -> {{Type}} -> {Type} -> Type
adamc@234 79 con sql_exp :: {{Type}} -> {{Type}} -> {Type} -> Type -> Type
adamc@204 80
adamc@223 81 con sql_subset :: {{Type}} -> {{Type}} -> Type
adamc@223 82 val sql_subset : keep_drop :: {({Type} * {Type})}
adamc@354 83 -> sql_subset
adamc@354 84 (fold (fn nm (fields :: ({Type} * {Type}))
adamc@354 85 acc [[nm] ~ acc]
adamc@354 86 [fields.1 ~ fields.2] =>
adamc@354 87 [nm = fields.1 ++ fields.2]
adamc@354 88 ++ acc) [] keep_drop)
adamc@354 89 (fold (fn nm (fields :: ({Type} * {Type}))
adamc@354 90 acc [[nm] ~ acc] =>
adamc@354 91 [nm = fields.1] ++ acc)
adamc@354 92 [] keep_drop)
adamc@354 93 val sql_subset_all : tables :: {{Type}} -> sql_subset tables tables
adamc@223 94
adamc@229 95 val sql_query1 : tables ::: {{Type}}
adamc@354 96 -> grouped ::: {{Type}}
adamc@354 97 -> selectedFields ::: {{Type}}
adamc@354 98 -> selectedExps ::: {Type}
adamc@354 99 -> {From : $(fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] =>
adamc@354 100 [nm = sql_table fields] ++ acc)
adamc@354 101 [] tables),
adamc@354 102 Where : sql_exp tables [] [] bool,
adamc@354 103 GroupBy : sql_subset tables grouped,
adamc@354 104 Having : sql_exp grouped tables [] bool,
adamc@354 105 SelectFields : sql_subset grouped selectedFields,
adamc@354 106 SelectExps : $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
adamc@354 107 [nm = sql_exp grouped tables [] t]
adamc@354 108 ++ acc) [] selectedExps) }
adamc@354 109 -> sql_query1 tables selectedFields selectedExps
adamc@229 110
adamc@229 111 type sql_relop
adamc@229 112 val sql_union : sql_relop
adamc@229 113 val sql_intersect : sql_relop
adamc@229 114 val sql_except : sql_relop
adamc@260 115 val sql_relop : tables1 ::: {{Type}}
adamc@354 116 -> tables2 ::: {{Type}}
adamc@354 117 -> selectedFields ::: {{Type}}
adamc@354 118 -> selectedExps ::: {Type}
adamc@354 119 -> sql_relop
adamc@354 120 -> sql_query1 tables1 selectedFields selectedExps
adamc@354 121 -> sql_query1 tables2 selectedFields selectedExps
adamc@354 122 -> sql_query1 selectedFields selectedFields selectedExps
adamc@229 123
adamc@230 124 type sql_direction
adamc@230 125 val sql_asc : sql_direction
adamc@230 126 val sql_desc : sql_direction
adamc@230 127
adamc@234 128 con sql_order_by :: {{Type}} -> {Type} -> Type
adamc@234 129 val sql_order_by_Nil : tables ::: {{Type}} -> exps :: {Type} -> sql_order_by tables exps
adamc@234 130 val sql_order_by_Cons : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type
adamc@354 131 -> sql_exp tables [] exps t -> sql_direction
adamc@354 132 -> sql_order_by tables exps
adamc@354 133 -> sql_order_by tables exps
adamc@230 134
adamc@231 135 type sql_limit
adamc@231 136 val sql_no_limit : sql_limit
adamc@231 137 val sql_limit : int -> sql_limit
adamc@354 138
adamc@232 139 type sql_offset
adamc@232 140 val sql_no_offset : sql_offset
adamc@232 141 val sql_offset : int -> sql_offset
adamc@232 142
adamc@229 143 val sql_query : tables ::: {{Type}}
adamc@354 144 -> selectedFields ::: {{Type}}
adamc@354 145 -> selectedExps ::: {Type}
adamc@354 146 -> {Rows : sql_query1 tables selectedFields selectedExps,
adamc@354 147 OrderBy : sql_order_by tables selectedExps,
adamc@354 148 Limit : sql_limit,
adamc@354 149 Offset : sql_offset}
adamc@354 150 -> sql_query selectedFields selectedExps
adamc@204 151
adamc@354 152 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type}
adamc@354 153 -> fieldType ::: Type -> agg ::: {{Type}}
adamc@354 154 -> exps ::: {Type}
adamc@354 155 -> tab :: Name -> field :: Name
adamc@354 156 -> sql_exp
adamc@354 157 ([tab = [field = fieldType] ++ otherFields] ++ otherTabs)
adamc@354 158 agg exps fieldType
adamc@234 159
adamc@354 160 val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {Type}
adamc@354 161 -> nm :: Name
adamc@354 162 -> sql_exp tabs agg ([nm = t] ++ rest) t
adamc@209 163
adamc@221 164 class sql_injectable
adamc@221 165 val sql_bool : sql_injectable bool
adamc@221 166 val sql_int : sql_injectable int
adamc@221 167 val sql_float : sql_injectable float
adamc@221 168 val sql_string : sql_injectable string
adamc@437 169 val sql_time : sql_injectable time
adamc@354 170 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@354 171 -> t ::: Type
adamc@354 172 -> sql_injectable t -> t -> sql_exp tables agg exps t
adamc@209 173
adamc@220 174 con sql_unary :: Type -> Type -> Type
adamc@220 175 val sql_not : sql_unary bool bool
adamc@354 176 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@354 177 -> arg ::: Type -> res ::: Type
adamc@354 178 -> sql_unary arg res -> sql_exp tables agg exps arg
adamc@354 179 -> sql_exp tables agg exps res
adamc@220 180
adamc@220 181 con sql_binary :: Type -> Type -> Type -> Type
adamc@220 182 val sql_and : sql_binary bool bool bool
adamc@220 183 val sql_or : sql_binary bool bool bool
adamc@234 184 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@354 185 -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
adamc@354 186 -> sql_binary arg1 arg2 res -> sql_exp tables agg exps arg1
adamc@354 187 -> sql_exp tables agg exps arg2
adamc@354 188 -> sql_exp tables agg exps res
adamc@220 189
adamc@219 190 type sql_comparison
adamc@219 191 val sql_eq : sql_comparison
adamc@219 192 val sql_ne : sql_comparison
adamc@219 193 val sql_lt : sql_comparison
adamc@219 194 val sql_le : sql_comparison
adamc@219 195 val sql_gt : sql_comparison
adamc@219 196 val sql_ge : sql_comparison
adamc@253 197 val sql_comparison : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@236 198 -> t ::: Type
adamc@253 199 -> sql_comparison
adamc@234 200 -> sql_exp tables agg exps t -> sql_exp tables agg exps t
adamc@234 201 -> sql_exp tables agg exps bool
adamc@203 202
adamc@235 203 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@354 204 -> unit -> sql_exp tables agg exps int
adamc@235 205
adamc@236 206 con sql_aggregate :: Type -> Type
adamc@354 207 val sql_aggregate : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@354 208 -> t ::: Type
adamc@354 209 -> sql_aggregate t -> sql_exp agg agg exps t
adamc@354 210 -> sql_exp tables agg exps t
adamc@236 211
adamc@236 212 class sql_summable
adamc@236 213 val sql_summable_int : sql_summable int
adamc@236 214 val sql_summable_float : sql_summable float
adamc@236 215 val sql_avg : t ::: Type -> sql_summable t -> sql_aggregate t
adamc@236 216 val sql_sum : t ::: Type -> sql_summable t -> sql_aggregate t
adamc@236 217
adamc@236 218 class sql_maxable
adamc@236 219 val sql_maxable_int : sql_maxable int
adamc@236 220 val sql_maxable_float : sql_maxable float
adamc@236 221 val sql_maxable_string : sql_maxable string
adamc@437 222 val sql_maxable_time : sql_maxable time
adamc@236 223 val sql_max : t ::: Type -> sql_maxable t -> sql_aggregate t
adamc@236 224 val sql_min : t ::: Type -> sql_maxable t -> sql_aggregate t
adamc@236 225
adamc@441 226 con sql_nfunc :: Type -> Type
adamc@441 227 val sql_nfunc : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@441 228 -> t ::: Type
adamc@441 229 -> sql_nfunc t -> sql_exp tables agg exps t
adamc@441 230 val sql_current_timestamp : sql_nfunc time
adamc@441 231
adamc@235 232
adamc@243 233 (*** Executing queries *)
adamc@243 234
adamc@243 235 con transaction :: Type -> Type
adamc@243 236 val return : t ::: Type
adamc@354 237 -> t -> transaction t
adamc@243 238 val bind : t1 ::: Type -> t2 ::: Type
adamc@354 239 -> transaction t1 -> (t1 -> transaction t2)
adamc@354 240 -> transaction t2
adamc@243 241
adamc@354 242 val query : tables ::: {{Type}} -> exps ::: {Type}
adamc@354 243 -> fn [tables ~ exps] =>
adamc@354 244 state ::: Type
adamc@354 245 -> sql_query tables exps
adamc@356 246 -> ($(exps ++ fold (fn nm (fields :: {Type}) acc [[nm] ~ acc] =>
adamc@354 247 [nm = $fields] ++ acc) [] tables)
adamc@354 248 -> state
adamc@354 249 -> transaction state)
adamc@354 250 -> state
adamc@354 251 -> transaction state
adamc@243 252
adamc@243 253
adamc@299 254 (*** Database mutators *)
adamc@299 255
adamc@299 256 type dml
adamc@299 257 val dml : dml -> transaction unit
adamc@299 258
adamc@299 259 val insert : fields ::: {Type}
adamc@354 260 -> sql_table fields
adamc@354 261 -> $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
adamc@354 262 [nm = sql_exp [] [] [] t] ++ acc)
adamc@354 263 [] fields)
adamc@354 264 -> dml
adamc@299 265
adamc@403 266 val update : unchanged ::: {Type} -> changed :: {Type} ->
adamc@354 267 fn [changed ~ unchanged] =>
adamc@354 268 $(fold (fn nm (t :: Type) acc [[nm] ~ acc] =>
adamc@354 269 [nm = sql_exp [T = changed ++ unchanged] [] [] t]
adamc@354 270 ++ acc)
adamc@354 271 [] changed)
adamc@354 272 -> sql_table (changed ++ unchanged)
adamc@354 273 -> sql_exp [T = changed ++ unchanged] [] [] bool
adamc@354 274 -> dml
adamc@299 275
adamc@299 276 val delete : fields ::: {Type}
adamc@354 277 -> sql_table fields
adamc@354 278 -> sql_exp [T = fields] [] [] bool
adamc@354 279 -> dml
adamc@299 280
adamc@338 281 (*** Sequences *)
adamc@338 282
adamc@338 283 type sql_sequence
adamc@338 284 val nextval : sql_sequence -> transaction int
adamc@338 285
adamc@299 286
adamc@203 287 (** XML *)
adamc@203 288
adamc@139 289 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
adamc@91 290
adamc@91 291
adamc@139 292 con xml :: {Unit} -> {Type} -> {Type} -> Type
adamc@141 293 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
adamc@354 294 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type}
adamc@354 295 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
adamc@354 296 -> useOuter ::: {Type} -> useInner ::: {Type}
adamc@354 297 -> bindOuter ::: {Type} -> bindInner ::: {Type}
adamc@354 298 -> fn [attrsGiven ~ attrsAbsent]
adamc@354 299 [useOuter ~ useInner]
adamc@354 300 [bindOuter ~ bindInner] =>
adamc@354 301 $attrsGiven
adamc@354 302 -> tag (attrsGiven ++ attrsAbsent)
adamc@354 303 ctxOuter ctxInner useOuter bindOuter
adamc@354 304 -> xml ctxInner useInner bindInner
adamc@354 305 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
adamc@140 306 val join : ctx ::: {Unit}
adamc@139 307 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
adamc@354 308 -> fn [use1 ~ bind1] [bind1 ~ bind2] =>
adamc@354 309 xml ctx use1 bind1
adamc@354 310 -> xml ctx (use1 ++ bind1) bind2
adamc@354 311 -> xml ctx use1 (bind1 ++ bind2)
adamc@354 312 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type}
adamc@354 313 -> bind ::: {Type}
adamc@354 314 -> fn [use1 ~ use2] =>
adamc@354 315 xml ctx use1 bind
adamc@354 316 -> xml ctx (use1 ++ use2) bind
adamc@91 317
adamc@110 318 con xhtml = xml [Html]
adamc@139 319 con page = xhtml [] []
adamc@325 320 con xbody = xml [Body] [] []
adamc@326 321 con xtr = xml [Body, Tr] [] []
adamc@361 322 con xform = xml [Body, Form] [] []
adamc@110 323
adamc@204 324 (*** HTML details *)
adamc@204 325
adamc@140 326 con html = [Html]
adamc@140 327 con head = [Head]
adamc@140 328 con body = [Body]
adamc@361 329 con form = [Body, Form]
adamc@332 330 con tabl = [Body, Table]
adamc@332 331 con tr = [Body, Tr]
adamc@93 332
adamc@140 333 val head : unit -> tag [] html head [] []
adamc@140 334 val title : unit -> tag [] head [] [] []
adamc@110 335
adamc@140 336 val body : unit -> tag [] html body [] []
adamc@354 337 con bodyTag = fn (attrs :: {Type}) =>
adamc@354 338 ctx ::: {Unit} ->
adamc@354 339 fn [[Body] ~ ctx] =>
adamc@354 340 unit -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
adamc@354 341 con bodyTagStandalone = fn (attrs :: {Type}) =>
adamc@354 342 ctx ::: {Unit}
adamc@354 343 -> fn [[Body] ~ ctx] =>
adamc@354 344 unit -> tag attrs ([Body] ++ ctx) [] [] []
adamc@141 345
adamc@141 346 val br : bodyTagStandalone []
adamc@119 347
adamc@140 348 val p : bodyTag []
adamc@140 349 val b : bodyTag []
adamc@140 350 val i : bodyTag []
adamc@407 351 val tt : bodyTag []
adamc@140 352 val font : bodyTag [Size = int, Face = string]
adamc@140 353
adamc@140 354 val h1 : bodyTag []
adamc@140 355 val li : bodyTag []
adamc@140 356
adamc@410 357 val hr : bodyTag []
adamc@410 358
adamc@280 359 val a : bodyTag [Link = transaction page]
adamc@140 360
adamc@361 361 val form : ctx ::: {Unit} -> bind ::: {Type}
adamc@354 362 -> fn [[Body] ~ ctx] =>
adamc@354 363 xml form [] bind
adamc@354 364 -> xml ([Body] ++ ctx) [] []
adamc@361 365 con formTag = fn (ty :: Type) (inner :: {Unit}) (attrs :: {Type}) =>
adamc@354 366 ctx ::: {Unit}
adamc@361 367 -> fn [[Form] ~ ctx] =>
adamc@354 368 nm :: Name -> unit
adamc@361 369 -> tag attrs ([Form] ++ ctx) inner [] [nm = ty]
adamc@361 370 val textbox : formTag string [] [Value = string]
adamc@361 371 val password : formTag string [] []
adamc@361 372 val textarea : formTag string [] []
adamc@153 373
adamc@361 374 val checkbox : formTag bool [] [Checked = bool]
adamc@190 375
adamc@153 376 con radio = [Body, Radio]
adamc@361 377 val radio : formTag string radio []
adamc@153 378 val radioOption : unit -> tag [Value = string] radio [] [] []
adamc@142 379
adamc@154 380 con select = [Select]
adamc@361 381 val select : formTag string select []
adamc@422 382 val option : unit -> tag [Value = string, Selected = bool] select [] [] []
adamc@154 383
adamc@354 384 val submit : ctx ::: {Unit} -> use ::: {Type}
adamc@361 385 -> fn [[Form] ~ ctx] =>
adamc@354 386 unit
adamc@406 387 -> tag [Value = string, Action = $use -> transaction page]
adamc@361 388 ([Form] ++ ctx) ([Form] ++ ctx) use []
adamc@283 389
adamc@325 390 (*** Tables *)
adamc@325 391
adamc@406 392 val tabl : other ::: {Unit} -> fn [other ~ [Body, Table]] =>
adamc@406 393 unit -> tag [Border = int] ([Body] ++ other) ([Body, Table] ++ other) [] []
adamc@406 394 val tr : other ::: {Unit} -> fn [other ~ [Body, Table, Tr]] =>
adamc@406 395 unit -> tag [] ([Body, Table] ++ other) ([Body, Tr] ++ other) [] []
adamc@406 396 val th : other ::: {Unit} -> fn [other ~ [Body, Tr]] =>
adamc@406 397 unit -> tag [] ([Body, Tr] ++ other) ([Body] ++ other) [] []
adamc@406 398 val td : other ::: {Unit} -> fn [other ~ [Body, Tr]] =>
adamc@406 399 unit -> tag [] ([Body, Tr] ++ other) ([Body] ++ other) [] []
adamc@325 400
adamc@283 401
adamc@283 402 (** Aborting *)
adamc@283 403
adamc@283 404 val error : t ::: Type -> xml [Body] [] [] -> t