
30 Sep
2005
30 Sep
'05
9:47 a.m.
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
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