src/Pure/library.ML
changeset 4102 f746af27164b
parent 4063 0b19014b9155
child 4139 e1659fd7a221
equal deleted inserted replaced
4101:e8ad51c88be9 4102:f746af27164b
   576   in
   576   in
   577     dist ([], lst)
   577     dist ([], lst)
   578   end;
   578   end;
   579 
   579 
   580 fun distinct l = gen_distinct (op =) l;
   580 fun distinct l = gen_distinct (op =) l;
       
   581 
       
   582 (*tuned version of distinct -- eq wrt. strings in fst component*)
       
   583 fun distinct_fst_string lst =
       
   584   let
       
   585     fun mem_str ((_:string, _), []) = false
       
   586       | mem_str (p as (x, _), ((y, _) :: qs)) = x = y orelse mem_str (p, qs);
       
   587 
       
   588     fun dist (rev_seen, []) = rev rev_seen
       
   589       | dist (rev_seen, p :: ps) =
       
   590           if mem_str (p, rev_seen) then dist (rev_seen, ps)
       
   591           else dist (p :: rev_seen, ps);
       
   592   in
       
   593     dist ([], lst)
       
   594   end;
   581 
   595 
   582 
   596 
   583 (*returns the tail beginning with the first repeated element, or []*)
   597 (*returns the tail beginning with the first repeated element, or []*)
   584 fun findrep [] = []
   598 fun findrep [] = []
   585   | findrep (x :: xs) = if x mem xs then x :: xs else findrep xs;
   599   | findrep (x :: xs) = if x mem xs then x :: xs else findrep xs;