Last active
December 18, 2015 18:29
-
-
Save dpwiz/5826131 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
http://www.reddit.com/r/programming/ | |
lol | |
Юникод лол, смотрите, ЮНИКОД! |
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
{-# LANGUAGE TupleSections #-} | |
import qualified Data.Text.Lazy as TL | |
import qualified Data.Text.Lazy.IO as TL | |
import Data.Char (isLetter) | |
import Data.List (sortBy) | |
import Data.Function (on) | |
import qualified Data.HashMap.Strict as HM | |
import System.Environment (getArgs) | |
collect = sortBy (flip compare `on` snd) | |
. HM.toList | |
. HM.fromListWith (+) | |
. map (,1) | |
. filter (not . TL.null) | |
. TL.split (not . isLetter) | |
. TL.toLower | |
display (word, count) = do | |
TL.putStr word | |
putStr ": " | |
print count | |
main = do | |
[fname, count] <- getArgs | |
text <- TL.readFile fname | |
mapM_ display $ take (read count) (collect text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment