<div class="gmail_quote">Hi,</div><div class="gmail_quote"><br></div><div class="gmail_quote">On 28 September 2010 10:33, Martin Tomko <span dir="ltr">&lt;<a href="mailto:martin.tomko@geo.uzh.ch">martin.tomko@geo.uzh.ch</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I have a list of (a,a) tuples, and am trying something like nub, but also matching for symmetrical tuples.</blockquote>
</div><div><br></div>You can of course do this. One approach would be to simply &#39;fix&#39; the tuples according to some ordering, and then use standard nub - or a better one.<div><br></div><div>But to me, the real question is this: If the order of your tuples to don&#39;t matter, do you actually need tuples? There are other types in which the order of the elements in a container does not change the meaning; such as a set. You may want to use a Set from Data.Set, or you can define a pair type in which ordering doesn&#39;t matter. It will end up being a cardinality restricted set type though.</div>
<div><br></div><div>If you just want to get it working, here is some code for the first option:</div><div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">nubSym :: Ord a =&gt; [(a,a)] -&gt; [(a,a)]</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">nubSym = nub . map fix</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  where fix (a,b) | a &gt; b = (b,a)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        fix p = p</font></div><div><br></div>Cheers,
</div><div>Ozgur</div>