[core libraries] Proposal: Make default impls for foldl1 and foldr1 lazier

Edward Kmett ekmett at gmail.com
Thu Oct 30 16:53:39 UTC 2014


+1 from me.

On Wed, Oct 29, 2014 at 3:08 PM, David Feuer <david.feuer at gmail.com> wrote:

> We currently have (in Data.Foldable)
>
>     foldr1 :: (a -> a -> a) -> t a -> a
>     foldr1 f xs = fromMaybe (error "foldr1: empty structure")
>                     (foldr mf Nothing xs)
>       where
>         mf x Nothing = Just x
>         mf x (Just y) = Just (f x y)
>
> and something similar for foldl1. This is strict in the entire spine,
> unlike the list version, because it has to get all the way to the end of
> the list before it starts laying down Justs. I propose we change this to
> the obvious:
>
>     foldr1 :: (a -> a -> a) -> t a -> a
>     foldr1 f xs = fromMaybe (error "foldr1: empty structure")
>                     (foldr mf Nothing xs)
>       where
>         mf x r = Just $ case r of
>                           Nothing -> x
>                           Just y  -> f x y
>
> Since GHC 7.10.1 is fast approaching, I doubt we have the usual two weeks
> to discuss this, so please speak up as soon as you can if you have concerns.
>
> --
> You received this message because you are subscribed to the Google Groups
> "haskell-core-libraries" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to haskell-core-libraries+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141030/2fcfa576/attachment-0001.html>


More information about the Libraries mailing list