hashmap withdrawal and poor haskell style

Remi Turk remi@abcweb.nl
Wed, 3 Apr 2002 19:22:13 +0200

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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)
		=3D putStrLn $ letter : replicate count '*'

countLetters    :: String -> [(Char, Integer)]
countLetters letters
		=3D fmToList $ addListToFM_C (+) emptyFM $ zip letters (repeat 1)

main    =3D getContents >>=3D mapM_ printCount . countLetters . filter isAl=

Happy Hacking


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 =3D CC90 A1BA CF6D 891C 5B88  C543 6C5F C469 8F20 70F4

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org