annotate lib/basis.urs @ 289:0cc956a3216f

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