[Haskell-cafe] function unique

Neil Mitchell ndmitchell at gmail.com
Wed Jul 11 15:34:06 EDT 2007


Hi

> unique = unique' []
>
> unique' _ [] = []
> unique' history (x:xs) = if x `elem` history
>   then next
>   else (x:next) where next = (uniq' (x:hist) xs)

You can express this more neatly:

unique' _ [] = []
unique' history (x:xs) = [x | x `notElem` history] ++ unique' (x:history) xs

Thanks

Neil


More information about the Haskell-Cafe mailing list