Last active
August 29, 2015 14:16
-
-
Save harlanhaskins/6789ddc13e73dc5c5569 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 System.IO (getContents) | |
import Data.Map (fromListWith, toList) | |
import Data.List (sortBy) | |
import Data.Ord (comparing) | |
import Data.Char (toLower, isLetter) | |
countedWords = toList . fromListWith (+) . map (flip (,) 1) | |
showTuple (item, count) = "word: " ++ item ++ " count: " ++ show count | |
normalized = map toLower . filter isLetter | |
main = getContents >>= mapM_ (putStrLn . showTuple) | |
. sortBy (flip (comparing snd)) | |
. countedWords | |
. map normalized | |
. words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment