[Haskell-cafe] Re: Haskell version of Norvig's Python Spelling Corrector

Pete Kazmier pete-expires-20070615 at kazmier.com
Sun Apr 22 16:00:45 EDT 2007

Derek Elkins <derek.a.elkins at gmail.com> writes:

>> After reading Bryan's post, I switched my right fold to a strict left
>> fold and almost tripled my original speed.  Could someone provide some
>> guidelines on when to use each?  I thought foldr should be used when
>> building some large data structure such as the map I build.
>> Bryan, out of curiosity, is a non bytestring version of your code
>> faster?
> http://www.haskell.org/hawiki/StackOverflow

I read the article and understand it, but I am having a hard time
applying that specifically to my use of foldr.  Here is how I was
using foldr:

  type WordFreq   = M.Map B.ByteString Int
  train:: [B.ByteString] -> WordFreq
  train words = frequencyMap
        frequencyMap     = foldr incWordCount M.empty words
        incWordCount w m = M.insertWith (+) w 1 m

So is 'incWordCount' strict in its second argument?  I'm still not
sure exactly what that means.  According to the wiki page, if it is
strict in the second argument, I should have used foldl' instead of


More information about the Haskell-Cafe mailing list