Skip to content

Instantly share code, notes, and snippets.

@harlanhaskins
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harlanhaskins/6789ddc13e73dc5c5569 to your computer and use it in GitHub Desktop.
Save harlanhaskins/6789ddc13e73dc5c5569 to your computer and use it in GitHub Desktop.
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