[Haskell-beginners] Re: A better way?

Heinrich Apfelmus apfelmus at quantentunnel.de
Sun Feb 22 09:34:49 EST 2009

Patrick LeBoutillier wrote:
> Hi,
> I changed my code to :
> maxTableColumnWidths :: [[String]] -> [Int]
> maxTableColumnWidths = foldl' rowMax zeros
>   where rowMax = zipWith (\m f -> max (length f) m)
>         zeros = 0 : zeros
> but it still blows the stack. I don't understand why. Doesn't foldl'
> force the evaluation of each call to rowMax? If so then I don't see
> what causes the stack to get so big... unless I'm looking in the wrong
> place...
> Can anyone shed some light?

It does force the evaluation of each call to  rowMax  but only to weak
head normal form. In other words, it will only evaluate the list to
either a cons cell or an empty list

   blah   --->  blah : blah
           \->  []

See also




More information about the Beginners mailing list