Skip to content

Instantly share code, notes, and snippets.

@pqwy
Last active August 29, 2015 14:04
Show Gist options
  • Save pqwy/22d6df58f418f855aaa6 to your computer and use it in GitHub Desktop.
Save pqwy/22d6df58f418f855aaa6 to your computer and use it in GitHub Desktop.
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
--
@pqwy
Copy link
Author

pqwy commented Jul 22, 2014

Also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment