
22 Apr
2007
22 Apr
'07
11:53 p.m.
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