[Haskell-beginners] removing duplicate tuples (including
symmetrical ones)
edgar klerks
edgar.klerks at gmail.com
Tue Sep 28 06:01:54 EDT 2010
You made the same mistake :)
removeDuplTuples x:xs = nub(if ((snd x,fst x) `elem` xs) then
(removeDuplTuples xs) else ([x] ++ removeDuplTuples xs))
Should be:
removeDuplTuples (x:xs) = nub(if ((snd x,fst x) `elem` xs) then
(removeDuplTuples xs) else ([x] ++ removeDuplTuples xs))
You need to put parenthesis around x:xs.
Greets,
Edgar
On Tue, Sep 28, 2010 at 11:57 AM, Martin Tomko <martin.tomko at geo.uzh.ch>wrote:
> Hi Edgar,
> thanks for the help. I wanted to first test with nub, but I still cannot
> get it to work. I cannot see any missing parenthesis, but I retyped it this
> way to check:
>
>
> removeDuplTuples :: (Eq a) =>[(a,a)] -> [(a,a)]
> removeDuplTuples [] = []
> removeDuplTuples [b] = [b]
> removeDuplTuples x:xs = nub(if ((snd x,fst x) `elem` xs) then
> (removeDuplTuples xs) else ([x] ++ removeDuplTuples xs))
>
> still the same error
>
> What am I missing?
> Martin
>
>
> On 9/28/2010 11:45 AM, edgar klerks wrote:
>
> >You forgot the parenthesis. Parse error in pattern usually means a type in
> the input of one of your functions. Nub needs >elements that can be equal.
>
> type has to be typo.
> On Tue, Sep 28, 2010 at 11:44 AM, edgar klerks <edgar.klerks at gmail.com>wrote:
>
>> Hi Martin,
>>
>> You have some typos:
>>
>> import Data.List
>> removeDuplTuples :: (Eq a) => [(a,a)] -> [(a,a)]
>>
>> removeDuplTuples [] = []
>> removeDuplTuples [b] =
>> [b]
>> -- using the syntactic sugar for single element in list
>> removeDuplTuples (x:xs) = nub (if elem (snd x,fst x) xs then
>> removeDuplTuples xs else [x] ++ removeDuplTuples xs)
>> --------
>> You forgot the parenthesis. Parse error in pattern usually means a type in
>> the input of one of your functions. Nub needs elements that can be equal.
>>
>> Nub is quitte inefficient, if your elements can be ordered, there is a
>> more efficient version. It is something like:
>>
>> fmap head.group.sort $ [1,1,1,1,4,4,5,6,6,7,8,9]
>> [1,4,5,6,7,8,9]
>>
>> But I haven't test it thoroughly.
>>
>> Greets,
>>
>> Edgar
>>
>> On Tue, Sep 28, 2010 at 11:33 AM, Martin Tomko <martin.tomko at geo.uzh.ch>wrote:
>>
>>> Hi all,
>>> I apologize for spamming this forum so frequently, but there is noone I
>>> can turn to around here...
>>> I have a list of (a,a) tuples, and am trying something like nub, but also
>>> matching for symmetrical tuples. I implemented it using the template from
>>> delete from Prelude. Seems like my typse signature has some troubles (Paarse
>>> error in pattern) but I am not sure where the problem is.
>>>
>>> removeDuplTuples :: [(a,a)] -> [(a,a)]
>>> removeDuplTuples [] = []
>>> removeDuplTuples [b] = [b]
>>>
>>> -- using the syntactic sugar for single element in list
>>> removeDuplTuples x:xs = nub (if elem (snd x,fst x) xs then
>>> removeDuplTuples xs else [x] ++ removeDuplTuples xs)
>>>
>>> I assume the problem lies in elem (snd x,fst x) xs but I am not sure how
>>> to rewrite it.
>>>
>>> Thanks for all help,
>>> Martin
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100928/ab3c94d3/attachment.html
More information about the Beginners
mailing list