Also, (since I believe that sort is stable), (map last . group . sort) should work, and may have different performance characteristics (but requires an Ord constraint).<br><br><div class="gmail_quote">On Sat, Jun 4, 2011 at 12:52 PM, Christopher Howard <span dir="ltr">&lt;<a href="mailto:christopher.howard@frigidcode.com">christopher.howard@frigidcode.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On 06/04/2011 12:20 AM, Iustin Pop wrote:<br>
&gt; On Fri, Jun 03, 2011 at 11:49:01PM -0800, Christopher Howard wrote:<br>
&gt;&gt; On 06/03/2011 11:37 PM, Christopher Howard wrote:<br>
&gt;&gt;&gt; Weird request: For a certain application, the &quot;nub&quot; function from<br>
&gt;&gt;&gt; Data.List is exactly what I need... almost. Nub removes duplicates,<br>
&gt;&gt;&gt; keeping the /first/ occurrence of each element. However, I need a<br>
&gt;&gt;&gt; function that removes duplicates, keeping the /second/ occurrence of<br>
&gt;&gt;&gt; each element. There wouldn&#39;t happen to be a function already that does<br>
&gt;&gt;&gt; this, would there?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;m working with a custom type which is a member of Eq, but some of the<br>
&gt;&gt;&gt; data in the type is not used in the comparison. So it is important which<br>
&gt;&gt;&gt; of the two &quot;duplicates&quot; are actually saved.<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I should qualify this: By &quot;second&quot; I mean &quot;last&quot;. Of course, it is<br>
&gt;&gt; possible for there to be more than one duplicate of any given element in<br>
&gt;&gt; a list. E.g., if there are three identical elements in a list, I want<br>
&gt;&gt; the third one, not the second one.<br>
&gt;<br>
&gt; In that case, can&#39;t you simply revert the list, nub it, then revert<br>
&gt; again (i.e. reverse . nub . reverse)?<br>
&gt;<br>
&gt; regards,<br>
&gt; iustin<br>
&gt;<br>
<br>
</div>@iustin: Thanks, that should work well enough.<br>
<br>
@Edwards: I&#39;m not familiar with Data.Set, so I do not understand your<br>
solution.<br>
<div class="im"><br>
--<br>
<a href="http://frigidcode.com" target="_blank">frigidcode.com</a><br>
<a href="http://theologia.indicium.us" target="_blank">theologia.indicium.us</a><br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div>          Alex R</div></div><br>