annotate lib/basis.lig @ 225:5ac2cf59b839

Change [sql_field] type to get 'where' test to check again
author Adam Chlipala <adamc@hcoop.net>
date Thu, 21 Aug 2008 13:47:18 -0400
parents cb8a68964ebb
children 016d71e878c1
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@204 16 con sql_query :: {{Type}} -> Type
adamc@223 17 con sql_exp :: {{Type}} -> {{Type}} -> Type -> Type
adamc@204 18
adamc@223 19 con sql_subset :: {{Type}} -> {{Type}} -> Type
adamc@223 20 val sql_subset : keep_drop :: {({Type} * {Type})}
adamc@223 21 -> sql_subset
adamc@223 22 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
adamc@223 23 [nm] ~ acc => fields.1 ~ fields.2 =>
adamc@223 24 [nm = fields.1 ++ fields.2] ++ acc) [] keep_drop)
adamc@223 25 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
adamc@223 26 [nm] ~ acc =>
adamc@223 27 [nm = fields.1] ++ acc) [] keep_drop)
adamc@223 28 val sql_subset_all : tables :: {{Type}}
adamc@223 29 -> sql_subset tables tables
adamc@223 30
adamc@223 31 val sql_query : tables ::: {{Type}}
adamc@224 32 -> grouped ::: {{Type}}
adamc@223 33 -> selected ::: {{Type}}
adamc@223 34 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc =>
adamc@223 35 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables),
adamc@223 36 Where : sql_exp tables [] bool,
adamc@224 37 GroupBy : sql_subset tables grouped,
adamc@224 38 Having : sql_exp grouped tables bool,
adamc@224 39 SelectFields : sql_subset grouped selected}
adamc@223 40 -> sql_query selected
adamc@204 41
adamc@225 42 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
adamc@221 43 -> tab :: Name -> field :: Name
adamc@223 44 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg fieldType
adamc@209 45
adamc@221 46 class sql_injectable
adamc@221 47 val sql_bool : sql_injectable bool
adamc@221 48 val sql_int : sql_injectable int
adamc@221 49 val sql_float : sql_injectable float
adamc@221 50 val sql_string : sql_injectable string
adamc@223 51 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> t -> sql_injectable t -> sql_exp tables agg t
adamc@209 52
adamc@220 53 con sql_unary :: Type -> Type -> Type
adamc@220 54 val sql_not : sql_unary bool bool
adamc@223 55 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg ::: Type -> res ::: Type
adamc@223 56 -> sql_unary arg res -> sql_exp tables agg arg -> sql_exp tables agg res
adamc@220 57
adamc@220 58 con sql_binary :: Type -> Type -> Type -> Type
adamc@220 59 val sql_and : sql_binary bool bool bool
adamc@220 60 val sql_or : sql_binary bool bool bool
adamc@223 61 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
adamc@223 62 -> sql_binary arg1 arg2 res -> sql_exp tables agg arg1 -> sql_exp tables agg arg2 -> sql_exp tables agg res
adamc@220 63
adamc@219 64 type sql_comparison
adamc@219 65 val sql_eq : sql_comparison
adamc@219 66 val sql_ne : sql_comparison
adamc@219 67 val sql_lt : sql_comparison
adamc@219 68 val sql_le : sql_comparison
adamc@219 69 val sql_gt : sql_comparison
adamc@219 70 val sql_ge : sql_comparison
adamc@219 71 val sql_comparison : sql_comparison
adamc@223 72 -> tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> sql_exp tables agg t -> sql_exp tables agg t
adamc@223 73 -> sql_injectable t -> sql_exp tables agg bool
adamc@203 74
adamc@203 75 (** XML *)
adamc@203 76
adamc@139 77 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
adamc@91 78
adamc@91 79
adamc@139 80 con xml :: {Unit} -> {Type} -> {Type} -> Type
adamc@141 81 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
adamc@104 82 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent
adamc@139 83 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
adamc@139 84 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner
adamc@139 85 -> bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner
adamc@104 86 -> $attrsGiven
adamc@139 87 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter
adamc@139 88 -> xml ctxInner useInner bindInner
adamc@139 89 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
adamc@140 90 val join : ctx ::: {Unit}
adamc@139 91 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
adamc@139 92 -> use1 ~ bind1 -> bind1 ~ bind2
adamc@140 93 -> xml ctx use1 bind1
adamc@140 94 -> xml ctx (use1 ++ bind1) bind2
adamc@140 95 -> xml ctx use1 (bind1 ++ bind2)
adamc@148 96 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type}
adamc@148 97 -> use1 ~ use2
adamc@148 98 -> xml ctx use1 bind
adamc@148 99 -> xml ctx (use1 ++ use2) bind
adamc@91 100
adamc@110 101 con xhtml = xml [Html]
adamc@139 102 con page = xhtml [] []
adamc@110 103
adamc@204 104 (*** HTML details *)
adamc@204 105
adamc@140 106 con html = [Html]
adamc@140 107 con head = [Head]
adamc@140 108 con body = [Body]
adamc@141 109 con lform = [Body, LForm]
adamc@93 110
adamc@140 111 val head : unit -> tag [] html head [] []
adamc@140 112 val title : unit -> tag [] head [] [] []
adamc@110 113
adamc@140 114 val body : unit -> tag [] html body [] []
adamc@140 115 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
adamc@140 116 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
adamc@141 117 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
adamc@141 118 -> tag attrs ([Body] ++ ctx) [] [] []
adamc@141 119
adamc@141 120 val br : bodyTagStandalone []
adamc@119 121
adamc@140 122 val p : bodyTag []
adamc@140 123 val b : bodyTag []
adamc@140 124 val i : bodyTag []
adamc@140 125 val font : bodyTag [Size = int, Face = string]
adamc@140 126
adamc@140 127 val h1 : bodyTag []
adamc@140 128 val li : bodyTag []
adamc@140 129
adamc@140 130 val a : bodyTag [Link = page]
adamc@140 131
adamc@141 132 val lform : ctx ::: {Unit} -> [Body] ~ ctx -> bind ::: {Type}
adamc@141 133 -> xml lform [] bind
adamc@141 134 -> xml ([Body] ++ ctx) [] []
adamc@153 135 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} =>
adamc@141 136 ctx ::: {Unit} -> [LForm] ~ ctx
adamc@141 137 -> nm :: Name -> unit
adamc@153 138 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
adamc@153 139 val textbox : lformTag string [] []
adamc@155 140 val password : lformTag string [] []
adamc@153 141 val ltextarea : lformTag string [] []
adamc@153 142
adamc@190 143 val checkbox : lformTag bool [] []
adamc@190 144
adamc@153 145 con radio = [Body, Radio]
adamc@153 146 val radio : lformTag string radio []
adamc@153 147 val radioOption : unit -> tag [Value = string] radio [] [] []
adamc@142 148
adamc@154 149 con select = [Select]
adamc@154 150 val lselect : lformTag string select []
adamc@154 151 val loption : unit -> tag [Value = string] select [] [] []
adamc@154 152
adamc@142 153 val submit : ctx ::: {Unit} -> [LForm] ~ ctx
adamc@142 154 -> use ::: {Type} -> unit
adamc@142 155 -> tag [Action = $use -> page] ([LForm] ++ ctx) ([LForm] ++ ctx) use []