Last active
August 29, 2015 14:04
-
-
Save pqwy/22d6df58f418f855aaa6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import Data.Function | |
import Control.Arrow | |
import qualified Data.HashMap.Strict as M | |
import qualified Data.ByteString.Lazy.Char8 as BL | |
import qualified Data.ByteString.Char8 as BS | |
import Text.Printf | |
histo = M.toList . foldl' (\m x -> M.insertWith (+) x (1 :: Int) m) M.empty | |
count = sortBy (flip (compare `on` snd)) . histo . map BL.toStrict . BL.words | |
main = BL.getContents >>= mapM_ print . count where | |
print (s, n) = printf "- %s : %d\n" (BS.unpack s) n | |
-- | |
-- ghc -O2 --make words.hs | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also.