annotate lib/basis.urs @ 308:72480e249130

First UPDATE works
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Sep 2008 15:12:47 -0400
parents 99e4f39e820d
children e457d8972ff1
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@223 55 -> sql_subset
adamc@223 56 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
adamc@223 57 [nm] ~ acc => fields.1 ~ fields.2 =>
adamc@223 58 [nm = fields.1 ++ fields.2] ++ acc) [] keep_drop)
adamc@223 59 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
adamc@223 60 [nm] ~ acc =>
adamc@223 61 [nm = fields.1] ++ acc) [] keep_drop)
adamc@223 62 val sql_subset_all : tables :: {{Type}}
adamc@223 63 -> sql_subset tables tables
adamc@223 64
adamc@229 65 val sql_query1 : tables ::: {{Type}}
adamc@224 66 -> grouped ::: {{Type}}
adamc@233 67 -> selectedFields ::: {{Type}}
adamc@233 68 -> selectedExps ::: {Type}
adamc@223 69 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc =>
adamc@223 70 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables),
adamc@234 71 Where : sql_exp tables [] [] bool,
adamc@224 72 GroupBy : sql_subset tables grouped,
adamc@234 73 Having : sql_exp grouped tables [] bool,
adamc@233 74 SelectFields : sql_subset grouped selectedFields,
adamc@233 75 SelectExps : $(fold (fn nm => fn t :: Type => fn acc =>
adamc@234 76 [nm] ~ acc => [nm = sql_exp grouped tables [] t] ++ acc) [] selectedExps) }
adamc@233 77 -> sql_query1 tables selectedFields selectedExps
adamc@229 78
adamc@229 79 type sql_relop
adamc@229 80 val sql_union : sql_relop
adamc@229 81 val sql_intersect : sql_relop
adamc@229 82 val sql_except : sql_relop
adamc@260 83 val sql_relop : tables1 ::: {{Type}}
adamc@229 84 -> tables2 ::: {{Type}}
adamc@233 85 -> selectedFields ::: {{Type}}
adamc@233 86 -> selectedExps ::: {Type}
adamc@260 87 -> sql_relop
adamc@233 88 -> sql_query1 tables1 selectedFields selectedExps
adamc@233 89 -> sql_query1 tables2 selectedFields selectedExps
adamc@233 90 -> sql_query1 selectedFields selectedFields selectedExps
adamc@229 91
adamc@230 92 type sql_direction
adamc@230 93 val sql_asc : sql_direction
adamc@230 94 val sql_desc : sql_direction
adamc@230 95
adamc@234 96 con sql_order_by :: {{Type}} -> {Type} -> Type
adamc@234 97 val sql_order_by_Nil : tables ::: {{Type}} -> exps :: {Type} -> sql_order_by tables exps
adamc@234 98 val sql_order_by_Cons : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type
adamc@268 99 -> sql_exp tables [] exps t -> sql_direction -> sql_order_by tables exps
adamc@234 100 -> sql_order_by tables exps
adamc@230 101
adamc@231 102 type sql_limit
adamc@231 103 val sql_no_limit : sql_limit
adamc@231 104 val sql_limit : int -> sql_limit
adamc@231 105
adamc@232 106 type sql_offset
adamc@232 107 val sql_no_offset : sql_offset
adamc@232 108 val sql_offset : int -> sql_offset
adamc@232 109
adamc@229 110 val sql_query : tables ::: {{Type}}
adamc@233 111 -> selectedFields ::: {{Type}}
adamc@233 112 -> selectedExps ::: {Type}
adamc@233 113 -> {Rows : sql_query1 tables selectedFields selectedExps,
adamc@234 114 OrderBy : sql_order_by tables selectedExps,
adamc@232 115 Limit : sql_limit,
adamc@232 116 Offset : sql_offset}
adamc@233 117 -> sql_query selectedFields selectedExps
adamc@204 118
adamc@225 119 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
adamc@234 120 -> exps ::: {Type}
adamc@221 121 -> tab :: Name -> field :: Name
adamc@234 122 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg exps fieldType
adamc@234 123
adamc@234 124 val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {Type} -> nm :: Name
adamc@234 125 -> sql_exp tabs agg ([nm = t] ++ rest) t
adamc@209 126
adamc@221 127 class sql_injectable
adamc@221 128 val sql_bool : sql_injectable bool
adamc@221 129 val sql_int : sql_injectable int
adamc@221 130 val sql_float : sql_injectable float
adamc@221 131 val sql_string : sql_injectable string
adamc@234 132 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type
adamc@234 133 -> sql_injectable t -> t -> sql_exp tables agg exps t
adamc@209 134
adamc@220 135 con sql_unary :: Type -> Type -> Type
adamc@220 136 val sql_not : sql_unary bool bool
adamc@234 137 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> arg ::: Type -> res ::: Type
adamc@234 138 -> sql_unary arg res -> sql_exp tables agg exps arg -> sql_exp tables agg exps res
adamc@220 139
adamc@220 140 con sql_binary :: Type -> Type -> Type -> Type
adamc@220 141 val sql_and : sql_binary bool bool bool
adamc@220 142 val sql_or : sql_binary bool bool bool
adamc@234 143 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@234 144 -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
adamc@234 145 -> sql_binary arg1 arg2 res -> sql_exp tables agg exps arg1 -> sql_exp tables agg exps arg2
adamc@234 146 -> sql_exp tables agg exps res
adamc@220 147
adamc@219 148 type sql_comparison
adamc@219 149 val sql_eq : sql_comparison
adamc@219 150 val sql_ne : sql_comparison
adamc@219 151 val sql_lt : sql_comparison
adamc@219 152 val sql_le : sql_comparison
adamc@219 153 val sql_gt : sql_comparison
adamc@219 154 val sql_ge : sql_comparison
adamc@253 155 val sql_comparison : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@236 156 -> t ::: Type
adamc@253 157 -> sql_comparison
adamc@234 158 -> sql_exp tables agg exps t -> sql_exp tables agg exps t
adamc@234 159 -> sql_exp tables agg exps bool
adamc@203 160
adamc@235 161 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@235 162 -> unit -> sql_exp tables agg exps int
adamc@235 163
adamc@236 164 con sql_aggregate :: Type -> Type
adamc@236 165 val sql_aggregate : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type
adamc@236 166 -> sql_aggregate t -> sql_exp agg agg exps t -> sql_exp tables agg exps t
adamc@236 167
adamc@236 168 class sql_summable
adamc@236 169 val sql_summable_int : sql_summable int
adamc@236 170 val sql_summable_float : sql_summable float
adamc@236 171 val sql_avg : t ::: Type -> sql_summable t -> sql_aggregate t
adamc@236 172 val sql_sum : t ::: Type -> sql_summable t -> sql_aggregate t
adamc@236 173
adamc@236 174 class sql_maxable
adamc@236 175 val sql_maxable_int : sql_maxable int
adamc@236 176 val sql_maxable_float : sql_maxable float
adamc@236 177 val sql_maxable_string : sql_maxable string
adamc@236 178 val sql_max : t ::: Type -> sql_maxable t -> sql_aggregate t
adamc@236 179 val sql_min : t ::: Type -> sql_maxable t -> sql_aggregate t
adamc@236 180
adamc@235 181
adamc@243 182 (*** Executing queries *)
adamc@243 183
adamc@243 184 con transaction :: Type -> Type
adamc@243 185 val return : t ::: Type
adamc@243 186 -> t -> transaction t
adamc@243 187 val bind : t1 ::: Type -> t2 ::: Type
adamc@243 188 -> transaction t1 -> (t1 -> transaction t2)
adamc@243 189 -> transaction t2
adamc@243 190
adamc@251 191 val query : tables ::: {{Type}} -> exps ::: {Type} -> tables ~ exps
adamc@252 192 -> state ::: Type
adamc@243 193 -> sql_query tables exps
adamc@251 194 -> ($(exps ++ fold (fn nm (fields :: {Type}) acc => [nm] ~ acc => [nm = $fields] ++ acc) [] tables)
adamc@243 195 -> state
adamc@243 196 -> transaction state)
adamc@243 197 -> state
adamc@243 198 -> transaction state
adamc@243 199
adamc@243 200
adamc@299 201 (*** Database mutators *)
adamc@299 202
adamc@299 203 type dml
adamc@299 204 val dml : dml -> transaction unit
adamc@299 205
adamc@299 206 val insert : fields ::: {Type}
adamc@299 207 -> sql_table fields
adamc@302 208 -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc =>
adamc@306 209 [nm = sql_exp [T = fields] [] [] t] ++ acc) [] fields)
adamc@299 210 -> dml
adamc@299 211
adamc@306 212 val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged
adamc@306 213 -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc =>
adamc@306 214 [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed)
adamc@305 215 -> sql_table (changed ++ unchanged)
adamc@306 216 -> sql_exp [T = changed ++ unchanged] [] [] bool
adamc@299 217 -> dml
adamc@299 218
adamc@299 219 val delete : fields ::: {Type}
adamc@299 220 -> sql_table fields
adamc@306 221 -> sql_exp [T = fields] [] [] bool
adamc@299 222 -> dml
adamc@299 223
adamc@299 224
adamc@203 225 (** XML *)
adamc@203 226
adamc@139 227 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
adamc@91 228
adamc@91 229
adamc@139 230 con xml :: {Unit} -> {Type} -> {Type} -> Type
adamc@141 231 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
adamc@104 232 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent
adamc@139 233 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
adamc@139 234 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner
adamc@139 235 -> bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner
adamc@104 236 -> $attrsGiven
adamc@139 237 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter
adamc@139 238 -> xml ctxInner useInner bindInner
adamc@139 239 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
adamc@140 240 val join : ctx ::: {Unit}
adamc@139 241 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
adamc@139 242 -> use1 ~ bind1 -> bind1 ~ bind2
adamc@140 243 -> xml ctx use1 bind1
adamc@140 244 -> xml ctx (use1 ++ bind1) bind2
adamc@140 245 -> xml ctx use1 (bind1 ++ bind2)
adamc@148 246 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type}
adamc@148 247 -> use1 ~ use2
adamc@148 248 -> xml ctx use1 bind
adamc@148 249 -> xml ctx (use1 ++ use2) bind
adamc@91 250
adamc@110 251 con xhtml = xml [Html]
adamc@139 252 con page = xhtml [] []
adamc@110 253
adamc@204 254 (*** HTML details *)
adamc@204 255
adamc@140 256 con html = [Html]
adamc@140 257 con head = [Head]
adamc@140 258 con body = [Body]
adamc@141 259 con lform = [Body, LForm]
adamc@93 260
adamc@140 261 val head : unit -> tag [] html head [] []
adamc@140 262 val title : unit -> tag [] head [] [] []
adamc@110 263
adamc@140 264 val body : unit -> tag [] html body [] []
adamc@140 265 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
adamc@140 266 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
adamc@141 267 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
adamc@141 268 -> tag attrs ([Body] ++ ctx) [] [] []
adamc@141 269
adamc@141 270 val br : bodyTagStandalone []
adamc@119 271
adamc@140 272 val p : bodyTag []
adamc@140 273 val b : bodyTag []
adamc@140 274 val i : bodyTag []
adamc@140 275 val font : bodyTag [Size = int, Face = string]
adamc@140 276
adamc@140 277 val h1 : bodyTag []
adamc@140 278 val li : bodyTag []
adamc@140 279
adamc@280 280 val a : bodyTag [Link = transaction page]
adamc@140 281
adamc@141 282 val lform : ctx ::: {Unit} -> [Body] ~ ctx -> bind ::: {Type}
adamc@141 283 -> xml lform [] bind
adamc@141 284 -> xml ([Body] ++ ctx) [] []
adamc@153 285 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} =>
adamc@141 286 ctx ::: {Unit} -> [LForm] ~ ctx
adamc@141 287 -> nm :: Name -> unit
adamc@153 288 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
adamc@153 289 val textbox : lformTag string [] []
adamc@155 290 val password : lformTag string [] []
adamc@153 291 val ltextarea : lformTag string [] []
adamc@153 292
adamc@190 293 val checkbox : lformTag bool [] []
adamc@190 294
adamc@153 295 con radio = [Body, Radio]
adamc@153 296 val radio : lformTag string radio []
adamc@153 297 val radioOption : unit -> tag [Value = string] radio [] [] []
adamc@142 298
adamc@154 299 con select = [Select]
adamc@154 300 val lselect : lformTag string select []
adamc@154 301 val loption : unit -> tag [Value = string] select [] [] []
adamc@154 302
adamc@142 303 val submit : ctx ::: {Unit} -> [LForm] ~ ctx
adamc@142 304 -> use ::: {Type} -> unit
adamc@280 305 -> tag [Action = $use -> transaction page] ([LForm] ++ ctx) ([LForm] ++ ctx) use []
adamc@283 306
adamc@283 307
adamc@283 308 (** Aborting *)
adamc@283 309
adamc@283 310 val error : t ::: Type -> xml [Body] [] [] -> t