Data.Foldable.foldr1 too strict

Bertram Felgenhauer bertram.felgenhauer at
Thu Sep 27 17:36:00 CEST 2012

Dan Doel wrote:
> On Thu, Sep 27, 2012 at 10:09 AM, Brent Yorgey <byorgey at> 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?


More information about the Libraries mailing list