
27 Sep
2012
27 Sep
'12
11:36 a.m.
Dan Doel wrote:
On Thu, Sep 27, 2012 at 10:09 AM, Brent Yorgey
wrote: Isn't that still too strict? I would expect to see "abcdef" before the exception.
No, even foldr1 as hand-written on lists needs to look ahead. Normally it looks like:
foldr1 f [x] = x foldr1 f (x:xs) = f x (foldr1 xs)
[...]
Where it's [more] obvious that it will hit the bottom before it can yield the "def".
But we could define foldr1 f (x:xs) = foldr f x xs which would be more lazy. I see no advantage to defining foldr1 as in the standard library, am I missing anything? Bertram