annotate lib/basis.urs @ 389:acaf9d19fbb7

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