hashmap withdrawal and poor haskell style
Remi Turk
remi@abcweb.nl
Wed, 3 Apr 2002 19:22:13 +0200
--wRRV7LY7NUeQGEoC
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:
>=20
> Hello everyone,
>=20
> 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=
pha
--------------------
Happy Hacking
Remi
--=20
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
--wRRV7LY7NUeQGEoC
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE8qzpFbF/EaY8gcPQRAm8DAJ44i0avXmnavtDu+OOy1mdrBL88HwCfWsx+
GFJUUd1zm1wV8CwfqU2TN0k=
=X3DP
-----END PGP SIGNATURE-----
--wRRV7LY7NUeQGEoC--