Not sure if this is a little much, but try understanding this:
Code:
import Data.List (foldl')
import qualified Data.Map as M
import Data.Char
countWords = M.toList . foldl' count M.empty . words
where
count m wd = M.alter (
\key -> Just $ case key of
Nothing -> 1
Just n -> n + 1
) (normalize wd) m
normalize = map toLower . filter (not . flip elem ",.?!;:'\"")
Code:
*Main> countWords "The man in the red suit is the man in the kitchen."
[("in",2),("is",1),("kitchen",1),("man",2),("red",1),("suit",1),("the",4)]
Also, if you don't know about it, http://haskell.org/hoogle/ is a great resource. Same with #haskell on irc freenode.
Bookmarks