[Haskell-beginners] maximum: stack overflow?

Patrick LeBoutillier patrick.leboutillier at gmail.com
Thu Mar 12 22:35:11 EDT 2009

Hi all,

Why does finding the maximum element of a big list cause a stack overflow:

In ghci, if I print out a big list:

*Main> [1..1000000]

it takes a while but it prints. However, looking for the maximum element fails:

*Main> maximum [1..1000000]
*** Exception: stack overflow

It seems to me like maximum should just be going through the list one
by one and keeping track on the
largest element seen do far. Why does in need to keep the entire list
around (I presume), causing the stack overflow?

Patrick LeBoutillier
Rosemère, Québec, Canada

More information about the Beginners mailing list