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

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Apr 22 23:53:46 EDT 2007


On Sun, 2007-04-22 at 12:55 -0400, Pete Kazmier wrote:

> 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.

You are building a strict data structure, not a lazy one. You cannot use
that map until every element has been inserted into it, there are no
partial intermediate results you can use like say when you build a lazy
list. Hence it's better to use a strict left fold.

Rule of thumb: use a lazy fold to build lazy structures, use a strict
fold to build strict ones.

Duncan



More information about the Haskell-Cafe mailing list