annotate lib/basis.urs @ 268:bacd0ba869e1

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