Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: nub... almost (Benjamin Edwards)
----------------------------------------------------------------------
Message: 1
Date: Sat, 4 Jun 2011 09:53:07 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] nub... almost
To: Christopher Howard <[email protected]>, Haskell
Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 4 June 2011 09:20, Iustin Pop <[email protected]> wrote:
> On Fri, Jun 03, 2011 at 11:49:01PM -0800, Christopher Howard wrote:
> > On 06/03/2011 11:37 PM, Christopher Howard wrote:
> > > Weird request: For a certain application, the "nub" function from
> > > Data.List is exactly what I need... almost. Nub removes duplicates,
> > > keeping the /first/ occurrence of each element. However, I need a
> > > function that removes duplicates, keeping the /second/ occurrence of
> > > each element. There wouldn't happen to be a function already that does
> > > this, would there?
> > >
> > > I'm working with a custom type which is a member of Eq, but some of the
> > > data in the type is not used in the comparison. So it is important
> which
> > > of the two "duplicates" are actually saved.
> > >
> >
> > I should qualify this: By "second" I mean "last". Of course, it is
> > possible for there to be more than one duplicate of any given element in
> > a list. E.g., if there are three identical elements in a list, I want
> > the third one, not the second one.
>
> In that case, can't you simply revert the list, nub it, then revert
> again (i.e. reverse . nub . reverse)?
>
> regards,
> iustin
>
> This is a a much better solution... mine of course discards the ordering in
the list and so is totally bogus.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110604/1c35c562/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 9
****************************************