[Haskell-cafe] Function to detect duplicates

Gwern Branwen gwern0 at gmail.com
Wed Feb 24 15:25:04 EST 2010


2010/2/23 Jonas Almström Duregård <jonas.duregard at gmail.com>:
> Hi Rafael,
>
> I assume you will perform this operation on some very large lists, or
> performance would not be an issue. Have you tested if your optimized
> version is better than your initial one?
>
> You should compare your implementation against something like this:
>
> import qualified Data.Set as Set
> noneRepeated :: (Ord a) => [a] -> Bool
> noneRepeated = accum Set.empty where
>  accum _ [] = True
>  accum s (x:xs)
>    | Set.member x s = False
>    | otherwise      = accum (Set.insert x s) xs
>
> Also there is some discussion about the nub function that relates to
> this topic, e.g. http://buffered.io/2008/07/28/a-better-nub/.
>
> /Jonas

Or better yet, http://www.haskell.org/pipermail/libraries/2008-October/010778.html
Much more thorough and practical w/r/t to actually getting faster nubs
in the libraries.

-- 
gwern


More information about the Haskell-Cafe mailing list