Container-Datentypen (I)

Wörter-Statistik:
import Data.Map (Map)
import qualified Data.Map as M

count :: FilePath -> IO ()
count f = do
    cs <- readFile f
    let m = statistik $ words cs
    putStrLn $ show m
statistik :: [ String ] -> Map String Int
statistik ws = M.fromListWith (+) $ do
     w <- ws
     return ( w, 1 )



Johannes Waldmann 2011-01-18