On Fri, 8 Feb 2008, [EMAIL PROTECTED] wrote:
Hallo!
Let's suppose I have a list [a,b,c,d,c,d]. I'd like to write
a function that returns a new list without duplicates (in
the example [a,b,c,d]). How can I do that? What is the most
general way? I'd like to use the same function for a list
As noted, (Data.Set.toList . Data.Set.fromList) is the best traditional
solution if you don't care about order (or Data.Set.toAscList for a
sorted result).
If order is important, the new bijective Data.Bimap class
http://code.haskell.org/~scook0/haddock/bimap/Data-Bimap.html
may be your best
Dan Weston wrote:
Meanwhile, here is a hand-rolled solution to order-preserving nubbing:
import Data.List(groupBy,sortBy,sort)
import Data.Maybe(listToMaybe)
efficientNub :: (Ord a) = [a] - [a]
efficientNub = flip zip [0..]-- carry along index
sort
Hallo!
Let's suppose I have a list [a,b,c,d,c,d]. I'd like to write
a function that returns a new list without duplicates (in
the example [a,b,c,d]). How can I do that? What is the most
general way? I'd like to use the same function for a list of
Int or String or some other user defined data
On 8 Feb 2008, [EMAIL PROTECTED] wrote:
Hallo!
Let's suppose I have a list [a,b,c,d,c,d]. I'd like to write
a function that returns a new list without duplicates (in
the example [a,b,c,d]). How can I do that? What is the most
general way? I'd like to use the same function for a list of
2008/2/8 Jed Brown [EMAIL PROTECTED]:
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