Once again, many thanks to all who taught me about this small little problem. Don't even know there is init/last and thought there is only head/tail. But just for my curiosity, would the takeWhile still store the intermediate result till my result is reached ? If so, and my list is really very long(and I need to go to 1/2 of its length), I would still use a lot more memory than imperative method or even the foldl one(where in both case, I just take one element) ? --- Henning Thielemann <lemming@henning-thielemann.de> wrote:
No problem: last (takeWhile (<maxX) (scanl (+) 0 xs)) Convinced?
The first sum which exceeds the limit could be computed with head (dropWhile (<=maxX) (scanl (+) 0 xs))
__________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com