[Haskell-cafe] how to break foldl' ?

gary ng garyng2000 at yahoo.com
Fri Sep 30 09:47:42 EDT 2005


Still a bit confused.

My function is simply

f x y = if x < 100 then x + y else x

Sure the rest of y will not be touched(so if it is a
file reading operation, no actual i/o will ever be
performed) as they are not needed. But how would foldl
knows that my logic won't need some other item in the
list till the end ? So won't it call (f) X times even
though all these X times just do a test and return ?

--- Thomas Davie <tom.davie at gmail.com> wrote:

> 
> 
> 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.
> 
> Bob
> 
> 



		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the Haskell-Cafe mailing list