annotate lib/basis.urs @ 436:024478c34f4d

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