annotate lib/basis.lig @ 222:36fef91a6bbf

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