
On Wed, Apr 03, 2002 at 07:13:03AM -0500, Michal Wallace wrote:
Hello everyone,
I just wrote my first haskell program. I started with a simple python program and tried to see if I could port it to haskell. The program reads text from stdin and prints out a histogram of all the letters:
Well, this is not my first Haskell-program, but I'm definitely still a Haskell-newbie :-D I had saved a few hours of work some time ago so I only had to adapt my countWords.hs to countLetters.hs to do The Right Thing(tm) It took me about five minutes (this time...) ;-p I hope the way I used FiniteMap (at least GHC has it...) isn't considered cheating :-) -------------------- module Main where import Char import FiniteMap printCount :: (Char, Integer) -> IO () printCount (letter, count) = putStrLn $ letter : replicate count '*' countLetters :: String -> [(Char, Integer)] countLetters letters = fmToList $ addListToFM_C (+) emptyFM $ zip letters (repeat 1) main = getContents >>= mapM_ printCount . countLetters . filter isAlpha -------------------- Happy Hacking Remi -- See the light and feel my warm desire, Run through your veins like the evening sun It will live but no eyes will see it, I'll bless your name before I die. Key fingerprint = CC90 A1BA CF6D 891C 5B88 C543 6C5F C469 8F20 70F4