231 end; |
231 end; |
232 |
232 |
233 |
233 |
234 (* removing duplicates, preferring nicer names, roughly n log n *) |
234 (* removing duplicates, preferring nicer names, roughly n log n *) |
235 |
235 |
|
236 local |
|
237 |
|
238 val hidden_ord = bool_ord o pairself NameSpace.is_hidden; |
|
239 val qual_ord = int_ord o pairself (length o NameSpace.explode); |
|
240 val txt_ord = int_ord o pairself size; |
|
241 |
|
242 fun nicer_name x y = |
|
243 (case hidden_ord (x, y) of |
|
244 EQUAL => (case qual_ord (x, y) of EQUAL => txt_ord (x, y) | ord => ord) |
|
245 | ord => ord) <> GREATER; |
|
246 |
|
247 in |
|
248 |
|
249 fun nicer (Fact _) _ = true |
|
250 | nicer (PureThy.Name x) (PureThy.Name y) = nicer_name x y |
|
251 | nicer (PureThy.Name _) (Fact _) = false |
|
252 | nicer (PureThy.Name _) _ = true |
|
253 | nicer (NameSelection (x, _)) (NameSelection (y, _)) = nicer_name x y |
|
254 | nicer (NameSelection _) _ = false; |
|
255 |
|
256 end; |
|
257 |
236 fun rem_thm_dups xs = |
258 fun rem_thm_dups xs = |
237 let |
259 let |
238 fun nicer (Fact x) (Fact y) = size x <= size y |
|
239 | nicer (Fact _) _ = true |
|
240 | nicer (PureThy.Name x) (PureThy.Name y) = size x <= size y |
|
241 | nicer (PureThy.Name _) (Fact _) = false |
|
242 | nicer (PureThy.Name _) _ = true |
|
243 | nicer (NameSelection (x, _)) (NameSelection (y, _)) = size x <= size y |
|
244 | nicer (NameSelection _) _ = false; |
|
245 |
|
246 fun rem_cdups xs = |
260 fun rem_cdups xs = |
247 let |
261 let |
248 fun rem_c rev_seen [] = rev rev_seen |
262 fun rem_c rev_seen [] = rev rev_seen |
249 | rem_c rev_seen [x] = rem_c (x::rev_seen) [] |
263 | rem_c rev_seen [x] = rem_c (x::rev_seen) [] |
250 | rem_c rev_seen ((x as ((n,t),_))::(y as ((n',t'),_))::xs) = |
264 | rem_c rev_seen ((x as ((n,t),_))::(y as ((n',t'),_))::xs) = |