Data.Foldable.foldr1 too strict
Dan Doel
dan.doel at gmail.com
Thu Sep 27 16:32:20 CEST 2012
On Thu, Sep 27, 2012 at 10:09 AM, Brent Yorgey <byorgey at seas.upenn.edu> 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)
but this is of course sugar for:
foldr1 f (x:[]) = x
foldr1 f (x:xs) = f x (foldr1 f xs)
Where it's more obvious that it will hit the bottom before it can
yield the "def".
-- Dan
More information about the Libraries
mailing list