<div>Your second solution, a part from non preserving the ordering of the initial sequence, also requires the type of the list elements to be an instance of Ord.</div><div>I&#39;ve fixed a bug in your first version, where the return values of isIn where reversed.</div>
<div><br></div><div>Here they are:</div><div><br></div><div><br></div><div>module Main where</div><div><br></div><div>import Data.List (sort, group)</div><div><br></div><div>-- Need ordering on &quot;a&quot;</div><div>uniqueS :: Ord a =&gt; [a] -&gt; [a]</div>
<div>uniqueS = concat . filter (null . drop 1) . group . sort</div><div><br></div><div>-- Fixed Chaddai&#39;s solution</div><div>-- Only need equivalent relation on &quot;a&quot;</div><div>unique :: Eq a =&gt; [a] -&gt; [a]</div>
<div>unique xs = [x | x &lt;- xs, isIn x xs 2]</div><div>        where isIn :: Eq a =&gt; a -&gt; [a] -&gt; Int -&gt; Bool</div><div>              isIn _ _ 0 = False</div><div>              isIn _ [] _ = True</div><div>              isIn y (x:xs) n </div>
<div>                    | y == x    = isIn y xs (n-1)</div><div>                    | otherwise = isIn y xs n </div><div><br></div><div>main :: IO ()</div><div>main = do</div><div>        print $ uniqueS xs</div><div>        print $ unique xs</div>
<div>        where xs = [1,2,3,3,5,2,1,4]</div><div><br></div><div><br></div><div>L.</div><div><br></div><br><div class="gmail_quote">On Thu, Mar 29, 2012 at 9:30 AM, Chaddaï Fouché <span dir="ltr">&lt;<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.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 Thu, Mar 29, 2012 at 10:28 AM, Chaddaï Fouché<br>
&lt;<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>&gt; wrote:<br>
&gt;&gt; unique xs = nub (sort xs)<br>
<br>
</div>oops, I meant :<br>
<br>
&gt; unique = concat . filter (null . drop 1) . group . sort<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Jedaï<br>
</font></span></blockquote></div><br>