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@229
|
17 con sql_query1 :: {{Type}} -> {{Type}} -> Type
|
adamc@223
|
18 con sql_exp :: {{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@223
|
34 -> selected ::: {{Type}}
|
adamc@223
|
35 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc =>
|
adamc@223
|
36 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables),
|
adamc@223
|
37 Where : sql_exp tables [] bool,
|
adamc@224
|
38 GroupBy : sql_subset tables grouped,
|
adamc@224
|
39 Having : sql_exp grouped tables bool,
|
adamc@224
|
40 SelectFields : sql_subset grouped selected}
|
adamc@229
|
41 -> sql_query1 tables selected
|
adamc@229
|
42
|
adamc@229
|
43 type sql_relop
|
adamc@229
|
44 val sql_union : sql_relop
|
adamc@229
|
45 val sql_intersect : sql_relop
|
adamc@229
|
46 val sql_except : sql_relop
|
adamc@229
|
47 val sql_relop : sql_relop
|
adamc@229
|
48 -> tables1 ::: {{Type}}
|
adamc@229
|
49 -> tables2 ::: {{Type}}
|
adamc@229
|
50 -> selected ::: {{Type}}
|
adamc@229
|
51 -> sql_query1 tables1 selected -> sql_query1 tables2 selected -> sql_query1 selected selected
|
adamc@229
|
52
|
adamc@230
|
53 type sql_direction
|
adamc@230
|
54 val sql_asc : sql_direction
|
adamc@230
|
55 val sql_desc : sql_direction
|
adamc@230
|
56
|
adamc@230
|
57 con sql_order_by :: {{Type}} -> Type
|
adamc@230
|
58 val sql_order_by_Nil : tables :: {{Type}} -> sql_order_by tables
|
adamc@230
|
59 val sql_order_by_Cons : tables ::: {{Type}} -> t ::: Type
|
adamc@230
|
60 -> sql_exp tables [] t -> sql_order_by tables
|
adamc@230
|
61 -> sql_order_by tables
|
adamc@230
|
62
|
adamc@231
|
63 type sql_limit
|
adamc@231
|
64 val sql_no_limit : sql_limit
|
adamc@231
|
65 val sql_limit : int -> sql_limit
|
adamc@231
|
66
|
adamc@229
|
67 val sql_query : tables ::: {{Type}}
|
adamc@229
|
68 -> selected ::: {{Type}}
|
adamc@230
|
69 -> {Rows : sql_query1 tables selected,
|
adamc@231
|
70 OrderBy : sql_order_by tables,
|
adamc@231
|
71 Limit : sql_limit}
|
adamc@223
|
72 -> sql_query selected
|
adamc@204
|
73
|
adamc@225
|
74 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
|
adamc@221
|
75 -> tab :: Name -> field :: Name
|
adamc@223
|
76 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg fieldType
|
adamc@209
|
77
|
adamc@221
|
78 class sql_injectable
|
adamc@221
|
79 val sql_bool : sql_injectable bool
|
adamc@221
|
80 val sql_int : sql_injectable int
|
adamc@221
|
81 val sql_float : sql_injectable float
|
adamc@221
|
82 val sql_string : sql_injectable string
|
adamc@223
|
83 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> t -> sql_injectable t -> sql_exp tables agg t
|
adamc@209
|
84
|
adamc@220
|
85 con sql_unary :: Type -> Type -> Type
|
adamc@220
|
86 val sql_not : sql_unary bool bool
|
adamc@223
|
87 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg ::: Type -> res ::: Type
|
adamc@223
|
88 -> sql_unary arg res -> sql_exp tables agg arg -> sql_exp tables agg res
|
adamc@220
|
89
|
adamc@220
|
90 con sql_binary :: Type -> Type -> Type -> Type
|
adamc@220
|
91 val sql_and : sql_binary bool bool bool
|
adamc@220
|
92 val sql_or : sql_binary bool bool bool
|
adamc@223
|
93 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
|
adamc@223
|
94 -> sql_binary arg1 arg2 res -> sql_exp tables agg arg1 -> sql_exp tables agg arg2 -> sql_exp tables agg res
|
adamc@220
|
95
|
adamc@219
|
96 type sql_comparison
|
adamc@219
|
97 val sql_eq : sql_comparison
|
adamc@219
|
98 val sql_ne : sql_comparison
|
adamc@219
|
99 val sql_lt : sql_comparison
|
adamc@219
|
100 val sql_le : sql_comparison
|
adamc@219
|
101 val sql_gt : sql_comparison
|
adamc@219
|
102 val sql_ge : sql_comparison
|
adamc@219
|
103 val sql_comparison : sql_comparison
|
adamc@223
|
104 -> tables ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> sql_exp tables agg t -> sql_exp tables agg t
|
adamc@223
|
105 -> sql_injectable t -> sql_exp tables agg bool
|
adamc@203
|
106
|
adamc@203
|
107 (** XML *)
|
adamc@203
|
108
|
adamc@139
|
109 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
|
adamc@91
|
110
|
adamc@91
|
111
|
adamc@139
|
112 con xml :: {Unit} -> {Type} -> {Type} -> Type
|
adamc@141
|
113 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
|
adamc@104
|
114 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent
|
adamc@139
|
115 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
|
adamc@139
|
116 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner
|
adamc@139
|
117 -> bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner
|
adamc@104
|
118 -> $attrsGiven
|
adamc@139
|
119 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter
|
adamc@139
|
120 -> xml ctxInner useInner bindInner
|
adamc@139
|
121 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
|
adamc@140
|
122 val join : ctx ::: {Unit}
|
adamc@139
|
123 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
|
adamc@139
|
124 -> use1 ~ bind1 -> bind1 ~ bind2
|
adamc@140
|
125 -> xml ctx use1 bind1
|
adamc@140
|
126 -> xml ctx (use1 ++ bind1) bind2
|
adamc@140
|
127 -> xml ctx use1 (bind1 ++ bind2)
|
adamc@148
|
128 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type}
|
adamc@148
|
129 -> use1 ~ use2
|
adamc@148
|
130 -> xml ctx use1 bind
|
adamc@148
|
131 -> xml ctx (use1 ++ use2) bind
|
adamc@91
|
132
|
adamc@110
|
133 con xhtml = xml [Html]
|
adamc@139
|
134 con page = xhtml [] []
|
adamc@110
|
135
|
adamc@204
|
136 (*** HTML details *)
|
adamc@204
|
137
|
adamc@140
|
138 con html = [Html]
|
adamc@140
|
139 con head = [Head]
|
adamc@140
|
140 con body = [Body]
|
adamc@141
|
141 con lform = [Body, LForm]
|
adamc@93
|
142
|
adamc@140
|
143 val head : unit -> tag [] html head [] []
|
adamc@140
|
144 val title : unit -> tag [] head [] [] []
|
adamc@110
|
145
|
adamc@140
|
146 val body : unit -> tag [] html body [] []
|
adamc@140
|
147 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@140
|
148 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
|
adamc@141
|
149 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@141
|
150 -> tag attrs ([Body] ++ ctx) [] [] []
|
adamc@141
|
151
|
adamc@141
|
152 val br : bodyTagStandalone []
|
adamc@119
|
153
|
adamc@140
|
154 val p : bodyTag []
|
adamc@140
|
155 val b : bodyTag []
|
adamc@140
|
156 val i : bodyTag []
|
adamc@140
|
157 val font : bodyTag [Size = int, Face = string]
|
adamc@140
|
158
|
adamc@140
|
159 val h1 : bodyTag []
|
adamc@140
|
160 val li : bodyTag []
|
adamc@140
|
161
|
adamc@140
|
162 val a : bodyTag [Link = page]
|
adamc@140
|
163
|
adamc@141
|
164 val lform : ctx ::: {Unit} -> [Body] ~ ctx -> bind ::: {Type}
|
adamc@141
|
165 -> xml lform [] bind
|
adamc@141
|
166 -> xml ([Body] ++ ctx) [] []
|
adamc@153
|
167 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} =>
|
adamc@141
|
168 ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@141
|
169 -> nm :: Name -> unit
|
adamc@153
|
170 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
|
adamc@153
|
171 val textbox : lformTag string [] []
|
adamc@155
|
172 val password : lformTag string [] []
|
adamc@153
|
173 val ltextarea : lformTag string [] []
|
adamc@153
|
174
|
adamc@190
|
175 val checkbox : lformTag bool [] []
|
adamc@190
|
176
|
adamc@153
|
177 con radio = [Body, Radio]
|
adamc@153
|
178 val radio : lformTag string radio []
|
adamc@153
|
179 val radioOption : unit -> tag [Value = string] radio [] [] []
|
adamc@142
|
180
|
adamc@154
|
181 con select = [Select]
|
adamc@154
|
182 val lselect : lformTag string select []
|
adamc@154
|
183 val loption : unit -> tag [Value = string] select [] [] []
|
adamc@154
|
184
|
adamc@142
|
185 val submit : ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@142
|
186 -> use ::: {Type} -> unit
|
adamc@142
|
187 -> tag [Action = $use -> page] ([LForm] ++ ctx) ([LForm] ++ ctx) use []
|