annotate lib/basis.urs @ 379:2b604ae76611

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