fork(1) download
  1. import Data.List (unfoldr)
  2. import System.Random
  3.  
  4. headTail (x:xs) = (x, xs)
  5.  
  6. bubbleSort :: Ord a => [a] -> [a]
  7. bubbleSort = unfoldr (fmap headTail . sort) where
  8. sort [] = Nothing
  9. sort (x:xs) = Just $ foldl f [x] xs
  10. f (z:zs) y | z < y = z : y : zs
  11. | otherwise = y : z : zs
  12.  
  13. main :: IO ()
  14. main = do
  15. xs <- randomRs ('a', 'z') `fmap` getStdGen
  16. print $ bubbleSort $ take 42 xs
  17.  
Success #stdin #stdout 0s 4884KB
stdin
Standard input is empty
stdout
"abccccdfffggghhijjjkkllmmnpqqqrstuuvwwwwyz"