comparison lib/ur/top.ur @ 1093:8d3aa6c7cee0

Make summary unification more conservative; infer implicit arguments after applications
author Adam Chlipala <adamc@hcoop.net>
date Sat, 26 Dec 2009 11:56:40 -0500
parents 25d491287358
children 7fc4e0087e50
comparison
equal deleted inserted replaced
1092:6f4b05fc4361 1093:8d3aa6c7cee0
7 -> tf [] -> tf r 7 -> tf [] -> tf r
8 8
9 fun fold [K] [tf :: {K} -> Type] 9 fun fold [K] [tf :: {K} -> Type]
10 (f : (nm :: Name -> v :: K -> r :: {K} -> [[nm] ~ r] => 10 (f : (nm :: Name -> v :: K -> r :: {K} -> [[nm] ~ r] =>
11 tf r -> tf ([nm = v] ++ r))) 11 tf r -> tf ([nm = v] ++ r)))
12 (i : tf []) [r :: {K}] (fl : folder r) = fl [tf] f i 12 (i : tf []) [r ::: {K}] (fl : folder r) = fl [tf] f i
13 13
14 structure Folder = struct 14 structure Folder = struct
15 fun nil [K] [tf :: {K} -> Type] 15 fun nil [K] [tf :: {K} -> Type]
16 (f : nm :: Name -> v :: K -> r :: {K} -> [[nm] ~ r] => 16 (f : nm :: Name -> v :: K -> r :: {K} -> [[nm] ~ r] =>
17 tf r -> tf ([nm = v] ++ r)) 17 tf r -> tf ([nm = v] ++ r))
90 | v => Some v) 90 | v => Some v)
91 91
92 fun txt [t] [ctx ::: {Unit}] [use ::: {Type}] (_ : show t) (v : t) = 92 fun txt [t] [ctx ::: {Unit}] [use ::: {Type}] (_ : show t) (v : t) =
93 cdata (show v) 93 cdata (show v)
94 94
95 fun map0 [K] [tf :: K -> Type] (f : t :: K -> tf t) [r :: {K}] (fl : folder r) = 95 fun map0 [K] [tf :: K -> Type] (f : t :: K -> tf t) [r ::: {K}] (fl : folder r) =
96 fl [fn r :: {K} => $(map tf r)] 96 fl [fn r :: {K} => $(map tf r)]
97 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc => 97 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc =>
98 acc ++ {nm = f [t]}) 98 acc ++ {nm = f [t]})
99 {} 99 {}
100 100
101 fun mp [K] [tf1 :: K -> Type] [tf2 :: K -> Type] (f : t ::: K -> tf1 t -> tf2 t) [r :: {K}] (fl : folder r) = 101 fun mp [K] [tf1 :: K -> Type] [tf2 :: K -> Type] (f : t ::: K -> tf1 t -> tf2 t) [r ::: {K}] (fl : folder r) =
102 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r)] 102 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r)]
103 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r => 103 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r =>
104 acc (r -- nm) ++ {nm = f r.nm}) 104 acc (r -- nm) ++ {nm = f r.nm})
105 (fn _ => {}) 105 (fn _ => {})
106 106
107 fun map2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] 107 fun map2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type]
108 (f : t ::: K -> tf1 t -> tf2 t -> tf3 t) [r :: {K}] (fl : folder r) = 108 (f : t ::: K -> tf1 t -> tf2 t -> tf3 t) [r ::: {K}] (fl : folder r) =
109 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r)] 109 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r)]
110 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r1 r2 => 110 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r1 r2 =>
111 acc (r1 -- nm) (r2 -- nm) ++ {nm = f r1.nm r2.nm}) 111 acc (r1 -- nm) (r2 -- nm) ++ {nm = f r1.nm r2.nm})
112 (fn _ _ => {}) 112 (fn _ _ => {})
113 113
114 fun map3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tf :: K -> Type] 114 fun map3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tf :: K -> Type]
115 (f : t ::: K -> tf1 t -> tf2 t -> tf3 t -> tf t) [r :: {K}] (fl : folder r) = 115 (f : t ::: K -> tf1 t -> tf2 t -> tf3 t -> tf t) [r ::: {K}] (fl : folder r) =
116 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> $(map tf r)] 116 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> $(map tf r)]
117 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r1 r2 r3 => 117 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] acc r1 r2 r3 =>
118 acc (r1 -- nm) (r2 -- nm) (r3 -- nm) ++ {nm = f r1.nm r2.nm r3.nm}) 118 acc (r1 -- nm) (r2 -- nm) (r3 -- nm) ++ {nm = f r1.nm r2.nm r3.nm})
119 (fn _ _ _ => {}) 119 (fn _ _ _ => {})
120 120
121 fun foldUR [tf :: Type] [tr :: {Unit} -> Type] 121 fun foldUR [tf :: Type] [tr :: {Unit} -> Type]
122 (f : nm :: Name -> rest :: {Unit} 122 (f : nm :: Name -> rest :: {Unit}
123 -> [[nm] ~ rest] => 123 -> [[nm] ~ rest] =>
124 tf -> tr rest -> tr ([nm] ++ rest)) 124 tf -> tr rest -> tr ([nm] ++ rest))
125 (i : tr []) [r :: {Unit}] (fl : folder r) = 125 (i : tr []) [r ::: {Unit}] (fl : folder r) =
126 fl [fn r :: {Unit} => $(mapU tf r) -> tr r] 126 fl [fn r :: {Unit} => $(mapU tf r) -> tr r]
127 (fn [nm :: Name] [t :: Unit] [rest :: {Unit}] [[nm] ~ rest] acc r => 127 (fn [nm :: Name] [t :: Unit] [rest :: {Unit}] [[nm] ~ rest] acc r =>
128 f [nm] [rest] ! r.nm (acc (r -- nm))) 128 f [nm] [rest] ! r.nm (acc (r -- nm)))
129 (fn _ => i) 129 (fn _ => i)
130 130
131 fun foldUR2 [tf1 :: Type] [tf2 :: Type] [tr :: {Unit} -> Type] 131 fun foldUR2 [tf1 :: Type] [tf2 :: Type] [tr :: {Unit} -> Type]
132 (f : nm :: Name -> rest :: {Unit} 132 (f : nm :: Name -> rest :: {Unit}
133 -> [[nm] ~ rest] => 133 -> [[nm] ~ rest] =>
134 tf1 -> tf2 -> tr rest -> tr ([nm] ++ rest)) 134 tf1 -> tf2 -> tr rest -> tr ([nm] ++ rest))
135 (i : tr []) [r :: {Unit}] (fl : folder r) = 135 (i : tr []) [r ::: {Unit}] (fl : folder r) =
136 fl [fn r :: {Unit} => $(mapU tf1 r) -> $(mapU tf2 r) -> tr r] 136 fl [fn r :: {Unit} => $(mapU tf1 r) -> $(mapU tf2 r) -> tr r]
137 (fn [nm :: Name] [t :: Unit] [rest :: {Unit}] [[nm] ~ rest] acc r1 r2 => 137 (fn [nm :: Name] [t :: Unit] [rest :: {Unit}] [[nm] ~ rest] acc r1 r2 =>
138 f [nm] [rest] ! r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 138 f [nm] [rest] ! r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
139 (fn _ _ => i) 139 (fn _ _ => i)
140 140
141 fun foldURX2 [tf1 :: Type] [tf2 :: Type] [ctx :: {Unit}] 141 fun foldURX2 [tf1 :: Type] [tf2 :: Type] [ctx :: {Unit}]
142 (f : nm :: Name -> rest :: {Unit} 142 (f : nm :: Name -> rest :: {Unit}
143 -> [[nm] ~ rest] => 143 -> [[nm] ~ rest] =>
144 tf1 -> tf2 -> xml ctx [] []) = 144 tf1 -> tf2 -> xml ctx [] []) =
145 foldUR2 [tf1] [tf2] [fn _ => xml ctx [] []] 145 @@foldUR2 [tf1] [tf2] [fn _ => xml ctx [] []]
146 (fn [nm :: Name] [rest :: {Unit}] [[nm] ~ rest] v1 v2 acc => 146 (fn [nm :: Name] [rest :: {Unit}] [[nm] ~ rest] v1 v2 acc =>
147 <xml>{f [nm] [rest] ! v1 v2}{acc}</xml>) 147 <xml>{f [nm] [rest] ! v1 v2}{acc}</xml>)
148 <xml/> 148 <xml/>
149 149
150 fun foldR [K] [tf :: K -> Type] [tr :: {K} -> Type] 150 fun foldR [K] [tf :: K -> Type] [tr :: {K} -> Type]
151 (f : nm :: Name -> t :: K -> rest :: {K} 151 (f : nm :: Name -> t :: K -> rest :: {K}
152 -> [[nm] ~ rest] => 152 -> [[nm] ~ rest] =>
153 tf t -> tr rest -> tr ([nm = t] ++ rest)) 153 tf t -> tr rest -> tr ([nm = t] ++ rest))
154 (i : tr []) [r :: {K}] (fl : folder r) = 154 (i : tr []) [r ::: {K}] (fl : folder r) =
155 fl [fn r :: {K} => $(map tf r) -> tr r] 155 fl [fn r :: {K} => $(map tf r) -> tr r]
156 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (acc : _ -> tr rest) r => 156 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] (acc : _ -> tr rest) r =>
157 f [nm] [t] [rest] ! r.nm (acc (r -- nm))) 157 f [nm] [t] [rest] ! r.nm (acc (r -- nm)))
158 (fn _ => i) 158 (fn _ => i)
159 159
160 fun foldR2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type] 160 fun foldR2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tr :: {K} -> Type]
161 (f : nm :: Name -> t :: K -> rest :: {K} 161 (f : nm :: Name -> t :: K -> rest :: {K}
162 -> [[nm] ~ rest] => 162 -> [[nm] ~ rest] =>
163 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest)) 163 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
164 (i : tr []) [r :: {K}] (fl : folder r) = 164 (i : tr []) [r ::: {K}] (fl : folder r) =
165 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> tr r] 165 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> tr r]
166 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 166 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
167 (acc : _ -> _ -> tr rest) r1 r2 => 167 (acc : _ -> _ -> tr rest) r1 r2 =>
168 f [nm] [t] [rest] ! r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm))) 168 f [nm] [t] [rest] ! r1.nm r2.nm (acc (r1 -- nm) (r2 -- nm)))
169 (fn _ _ => i) 169 (fn _ _ => i)
170 170
171 fun foldR3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tr :: {K} -> Type] 171 fun foldR3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [tr :: {K} -> Type]
172 (f : nm :: Name -> t :: K -> rest :: {K} 172 (f : nm :: Name -> t :: K -> rest :: {K}
173 -> [[nm] ~ rest] => 173 -> [[nm] ~ rest] =>
174 tf1 t -> tf2 t -> tf3 t -> tr rest -> tr ([nm = t] ++ rest)) 174 tf1 t -> tf2 t -> tf3 t -> tr rest -> tr ([nm = t] ++ rest))
175 (i : tr []) [r :: {K}] (fl : folder r) = 175 (i : tr []) [r ::: {K}] (fl : folder r) =
176 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> tr r] 176 fl [fn r :: {K} => $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> tr r]
177 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 177 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
178 (acc : _ -> _ -> _ -> tr rest) r1 r2 r3 => 178 (acc : _ -> _ -> _ -> tr rest) r1 r2 r3 =>
179 f [nm] [t] [rest] ! r1.nm r2.nm r3.nm (acc (r1 -- nm) (r2 -- nm) (r3 -- nm))) 179 f [nm] [t] [rest] ! r1.nm r2.nm r3.nm (acc (r1 -- nm) (r2 -- nm) (r3 -- nm)))
180 (fn _ _ _ => i) 180 (fn _ _ _ => i)
181 181
182 fun foldRX [K] [tf :: K -> Type] [ctx :: {Unit}] 182 fun foldRX [K] [tf :: K -> Type] [ctx :: {Unit}]
183 (f : nm :: Name -> t :: K -> rest :: {K} 183 (f : nm :: Name -> t :: K -> rest :: {K}
184 -> [[nm] ~ rest] => 184 -> [[nm] ~ rest] =>
185 tf t -> xml ctx [] []) = 185 tf t -> xml ctx [] []) =
186 foldR [tf] [fn _ => xml ctx [] []] 186 @@foldR [tf] [fn _ => xml ctx [] []]
187 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] r acc => 187 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] r acc =>
188 <xml>{f [nm] [t] [rest] ! r}{acc}</xml>) 188 <xml>{f [nm] [t] [rest] ! r}{acc}</xml>)
189 <xml/> 189 <xml/>
190 190
191 fun foldRX2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [ctx :: {Unit}] 191 fun foldRX2 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [ctx :: {Unit}]
192 (f : nm :: Name -> t :: K -> rest :: {K} 192 (f : nm :: Name -> t :: K -> rest :: {K}
193 -> [[nm] ~ rest] => 193 -> [[nm] ~ rest] =>
194 tf1 t -> tf2 t -> xml ctx [] []) = 194 tf1 t -> tf2 t -> xml ctx [] []) =
195 foldR2 [tf1] [tf2] [fn _ => xml ctx [] []] 195 @@foldR2 [tf1] [tf2] [fn _ => xml ctx [] []]
196 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 196 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
197 r1 r2 acc => 197 r1 r2 acc =>
198 <xml>{f [nm] [t] [rest] ! r1 r2}{acc}</xml>) 198 <xml>{f [nm] [t] [rest] ! r1 r2}{acc}</xml>)
199 <xml/> 199 <xml/>
200 200
201 fun foldRX3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [ctx :: {Unit}] 201 fun foldRX3 [K] [tf1 :: K -> Type] [tf2 :: K -> Type] [tf3 :: K -> Type] [ctx :: {Unit}]
202 (f : nm :: Name -> t :: K -> rest :: {K} 202 (f : nm :: Name -> t :: K -> rest :: {K}
203 -> [[nm] ~ rest] => 203 -> [[nm] ~ rest] =>
204 tf1 t -> tf2 t -> tf3 t -> xml ctx [] []) = 204 tf1 t -> tf2 t -> tf3 t -> xml ctx [] []) =
205 foldR3 [tf1] [tf2] [tf3] [fn _ => xml ctx [] []] 205 @@foldR3 [tf1] [tf2] [tf3] [fn _ => xml ctx [] []]
206 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest] 206 (fn [nm :: Name] [t :: K] [rest :: {K}] [[nm] ~ rest]
207 r1 r2 r3 acc => 207 r1 r2 r3 acc =>
208 <xml>{f [nm] [t] [rest] ! r1 r2 r3}{acc}</xml>) 208 <xml>{f [nm] [t] [rest] ! r1 r2 r3}{acc}</xml>)
209 <xml/> 209 <xml/>
210 210
211 fun queryL [tables] [exps] [tables ~ exps] (q : sql_query tables exps) = 211 fun queryL [tables] [exps] [tables ~ exps] (q : sql_query tables exps) =
212 query q 212 query q
213 (fn r ls => return (r :: ls)) 213 (fn r ls => return (r :: ls))
214 [] 214 []