[Haskell-cafe] Create a list without duplicates from a list with
duplicates
Dan Weston
westondan at imageworks.com
Mon Feb 11 15:32:53 EST 2008
Of course the most *general* way requires an Eq constraint:
> List.nub :: Eq a => [a] -> [a]
But there are better functions (already mentioned) with the less general
Ord constraint.
Int and String are instances of Ord. "some other user defined data type"
probably is too, but if you mean "any other user defined data type",
even Eq may not be satisfied, e.g.
> data NotEvenEq a = FuncsNotEq (a->a)
The hammer you use depends on what you're hammering on.
Dan
Henning Thielemann wrote:
> On Fri, 8 Feb 2008, news at lyra.net 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
>> Int or String or some other user defined data type.
>
> List.nub
More information about the Haskell-Cafe
mailing list