
30 Sep
2005
30 Sep
'05
3:23 p.m.
gary ng wrote:
Still a bit confused.
My function is simply
f x y = if x < 100 then x + y else x
Try this: sum_to_100 xs = foldr (\x k a -> if a < 100 then k $! (x+a) else a) id xs 0 As expected, (sum_to_100 [1..]) gives 105, without trying to find the end of an infinite list. You get your early-out semantics combined with strict evaluation. Udo.