annotate lib/basis.lig @ 239:fc6f04889bf2

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