[Haskell-cafe] how to break foldl' ?
Henning Thielemann
lemming at henning-thielemann.de
Fri Sep 30 11:14:54 EDT 2005
On Fri, 30 Sep 2005, gary ng wrote:
> 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.
http://www.haskell.org/ghc/docs/6.4/html/libraries/base/Data.List.html
> 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)
> ?
If you don't trust the compiler you can at least test if the rest of the
list is ignored: Run with an infinite list.
E.g.
last (takeWhile (<10) (scanl (+) 0 (repeat 1)))
More information about the Haskell-Cafe
mailing list