
12 Jul
2007
12 Jul
'07
5:37 p.m.
Now that I mention it, the base case is much less often called than the recursive case, so I would in hindsight flip the order of the two (mutually exclusive) partial function definitions: unique :: Eq a => [a] -> [a] unique (x:xs) = x : (unique . filter (/= x) $ xs) unique [] = [] This should be marginally more efficient. I doubt that GHC would automatically detect that a) they are mutually exclusive and b) the second is called less often than the first! Dan Dan Weston wrote:
Close. Actually, the author upstream (i.e. me) had in mind:
uniq :: Eq a => [a] -> [a] uniq [] = [] uniq (x:xs) = x : uniq (filter (/= x) xs)