Anonymous user
Word frequency: Difference between revisions
simplify
(simplify) |
|||
Line 2,503:
module Main where
import
import Data.
import
import Data.Ord (Down(..))
import System.IO (stdin, IOMode(..), openFile, hClose)
Line 2,531 ⟶ 2,529:
main = do
args <- getArgs
when (length args /= 1) (error "expecting 1 arg (number of words to print)")
let maxw = read $ head args -- no error handling, to simplify the example
▲ T.hGetContents hand >>= \contents -> do
freqtable <- frequencies $ filter (not . T.null) $ T.split isSpace $ T.map toLower contents
counts <-
Line 2,542 ⟶ 2,537:
cnt <- readIORef ref
return (w, cnt)
in mapM readRef $ M.toList freqtable
print $ take maxw $ sortOn
</lang>
{{Out}}
|