annotate lib/basis.urs @ 391:fe8f75f7e130

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