[Haskell-beginners] How would you improve this program?

Lorenzo Bolla lbolla at gmail.com
Sun Oct 9 22:11:35 CEST 2011


Hi all,
I'm new to Haskell and I'd like you to take a look at one of my programs and
tell me how you would improve it (in terms of efficiency, style, and so
on!).

The source code is here:
https://github.com/lbolla/stanford-cs240h/blob/master/lab1/lab1.hs
The program is an implementation of this problem:
http://www.scs.stanford.edu/11au-cs240h/labs/lab1.html (basically, counting
how many times a word appear in a text.)
(I'm not a Stanford student, so by helping me out you won't help me to cheat
my exam, don't worry!)

I've implemented 3 versions of the algorithm:

   1. a Haskell version using the standard "sort": read all the words from
   stdin, sort them and group them.
   2. a Haskell version using map: read all the words from stdin, stick each
   word in a Data.Map incrementing a counter if the word is already present in
   the map.
   3. a Python version using defaultdict.

I timed the different versions and the results are here:
https://github.com/lbolla/stanford-cs240h/blob/master/lab1/times.png.
The python version is the quickest (I stripped out the fancy formatting
before benchmarking, so IO is not responsible for the time difference).
Any comments on the graph, too?

Thanks a lot!
L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111009/5d58dabb/attachment.htm>


More information about the Beginners mailing list