
5 Jun
2012
5 Jun
'12
12:11 a.m.
Hi, 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()){ $freq{$item}++; } 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. Ian