Examples/Sort numbers

From HaskellWiki
Revision as of 03:07, 31 January 2007 by DonStewart (talk | contribs) (yay for code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


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.