Limitations of "maximum"

Kim-Ee Yeoh yeoh@cs.wisc.edu
Fri, 17 Jan 2003 10:36:25 -0600 (CST)


A newbie question: In Hugs, why does "maximum $ replicate n 0"
require space linear in n whereas "sum $ replicate n 0" appears
to have no such limit (in the sense that we don't get "ERROR - 
Garbage collection fails to reclaim sufficient space")?

The standard prelude defines both as basically foldl's -- maximum
is actually foldl1 max, so I'm a little confused here.

GHCi appears to require linear space for sum as well.

I guess the real question to ask is: is there a constant space version
of maximum, perhaps using strictness annotations?


Regards,
Kim-Ee