[Haskell-beginners] histogram over large data

Ian Knopke ian.knopke at gmail.com
Tue Jun 5 06:11:27 CEST 2012


I'd like to build a histogram, or even just a frequency count of some
categorical data from a large database. In a language such as perl I'd
do something like this:

my %freq; # hash
while (my $item = get_next_from_db()){

and then sum the hash values and divide the value of each key by the
sum to get the histogram.

Is there an easy way to do the same thing in Haskell? It looked like
an easy task but I seem to be having a lot of trouble getting this to
work properly, as it doesn't seem to be behaving very lazily. I'm
guessing I should be doing something with the State monad, but I'm not
very good at using that yet.


More information about the Beginners mailing list