Re: [Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-09 Thread Henning Thielemann
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

Re: [Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-08 Thread Dan Weston
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

Re: [Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-08 Thread Tillmann Rendel
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

[Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-08 Thread [EMAIL PROTECTED]
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

Re: [Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-08 Thread Jed Brown
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

Re: [Haskell-cafe] Create a list without duplicates from a list with duplicates

2008-02-08 Thread Felipe Lessa
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