Examples/Sort numbers
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.