[Haskell-beginners] maximum: stack overflow?
patrick.leboutillier at gmail.com
Thu Mar 12 22:35:11 EDT 2009
Why does finding the maximum element of a big list cause a stack overflow:
In ghci, if I print out a big list:
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?
Rosemère, Québec, Canada
More information about the Beginners