[Haskell-cafe] how to break foldl' ?

Thomas Davie tom.davie at gmail.com
Thu Sep 29 18:53:20 EDT 2005

On 30 Sep 2005, at 11:33, gary ng wrote:

> Hi,
> say if I want to sum a list of numbers but only until
> it hits a max limit.
> Currently, I control it through the function and
> basically do nothing when the max is hit. However, if
> the list is very long, would this mean the same
> function would be called for the rest of the list
> which can be a waste of cycle ? In an imperative
> language, I just break/return in the middle of the
> loop.

No - lazy evaluation guarantees that if a reduct is never needed, it  
is never reduced.  So as your function never needs the latter values  
in the list, it is never evaluated.


More information about the Haskell-Cafe mailing list