Examples/Sort numbers

From HaskellWiki
Jump to navigation Jump to search


Sort a list of numbers on stdin, display the sorted result to stdout.

import qualified Data.ByteString.Char8 as B
import Data.List

main = B.putStr . B.unlines . map (B.pack . show) . sort . unfoldr parse =<< B.getContents

parse !x | Just (n,y) <- B.readInt x = Just (n,B.tail y)
         | otherwise                 = Nothing

Should be pretty quick.