<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'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 "a"</div><div>uniqueS :: Ord a => [a] -> [a]</div>
<div>uniqueS = concat . filter (null . drop 1) . group . sort</div><div><br></div><div>-- Fixed Chaddai's solution</div><div>-- Only need equivalent relation on "a"</div><div>unique :: Eq a => [a] -> [a]</div>
<div>unique xs = [x | x <- xs, isIn x xs 2]</div><div> where isIn :: Eq a => a -> [a] -> Int -> 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"><<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>></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>
<<a href="mailto:chaddai.fouche@gmail.com">chaddai.fouche@gmail.com</a>> wrote:<br>
>> unique xs = nub (sort xs)<br>
<br>
</div>oops, I meant :<br>
<br>
> unique = concat . filter (null . drop 1) . group . sort<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Jedaï<br>
</font></span></blockquote></div><br>