HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Examples/Sort numbers

Categories: Code


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.

Retrieved from "http://haskell.org/haskellwiki/Examples/Sort_numbers"

This page has been accessed 835 times. This page was last modified 03:07, 31 January 2007. Recent content is available under a simple permissive license.