Last active
August 29, 2015 14:05
-
-
Save andyfriesen/825be8da046e3ed7f213 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| -- sort function, optimized for lists | |
| -- TODO - profiling | |
| sortBy compare = head . head . dropWhile (isn't unsafeCoerce . drop 1) . group . iterate bubble | |
| where | |
| bubble [] = [] | |
| bubble [x] = [x] | |
| bubble (x:y:ys) = | |
| if compare x y == GT | |
| then y:(bubble (x:ys)) | |
| else | |
| if compare x y == EQ | |
| then x:(bubble (y:ys)) | |
| else | |
| if compare x y == LT | |
| then x:(bubble (y:ys)) | |
| else x:y:(bubble ys) | |
| isn't f x = if f x then False else True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment