
8 Feb
2008
8 Feb
'08
7:25 a.m.
2008/2/8 Jed Brown
Look at Data.List:
nub :: (Eq a) => [a] -> [a] nub = nubBy (==)
nubBy :: (a -> a -> Bool) -> [a] -> [a] nubBy eq [] = [] nubBy eq (x:xs) = x : nubBy eq (filter (\ y -> not (eq x y)) xs)
And then there's also sort :: (Ord a) => [a] -> [a] which should have better performance, O(n log n) against O(n²) I guess, but of course will change the order of the elements. If you really don't mind the order at all, you could also use Data.Set in the first place. Cheers, -- Felipe.