Created
September 20, 2011 08:12
-
-
Save fritschy/1228611 to your computer and use it in GitHub Desktop.
sort -u for arbitrary haskell lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DecorateSortUniq where | |
import Data.List | |
decorateSortUniq :: Ord a => [a] -> [a] | |
decorateSortUniq = map snd . sortBy (\(a,_) (b,_)->compare a b) . uniq snd . sortBy (\(_,a) (_,b)->compare a b) . zip [0..] | |
where uniq f (x:y:xs) = if f x == f y then uniq f (x:xs) else x:uniq f (y:xs) | |
uniq _ (x:_) = [x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment