Proposal: (breaking change to avoid fragile breakage) change the definition of foldr2, zip, and zipWith

Joachim Breitner mail at joachim-breitner.de
Mon Sep 8 08:24:45 UTC 2014


Dear David,


Am Montag, den 08.09.2014, 02:58 -0400 schrieb David Feuer:
> It's been a couple weeks now, and no one's responded. 

that can happen. Usually not because noone cares, but because noone
knows what’s best. And also there was ICFP last week, which probably
kept people busy ... so don’t be discouraged by silence, and keep
following up on it.

> On Sun, Aug 24, 2014 at 3:22 PM, David Feuer <david.feuer at gmail.com> wrote:
> > BACKGROUND
> >
> > TRAC: #9495

> > SOLUTIONS
> >
> > 1. One solution, of course, is to eliminate unfoldr2/right, bringing GHC
> > into compliance with the Report. I really like this idea, but Joachim thinks
> > it is not worth the potential performance impact on code written before or
> > without regard for the change. We both agree that a reasonable alternative
> > is
> >
> > 3. Modify the baseline definition of unfoldr2 as follows:
> >
> > foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c
> > foldr2 k z = go
> >   where
> >     go [] ys = ys `seq` z
> >     go _xs [] = z
> >     go (x:xs) (y:ys) = k x y (go xs ys)
> >
> > This should, we believe, make the baseline definition fail where the one
> > fused by foldr2/right would fail, giving consistent semantics.

You already said that I agree with that solution, but I can re-state it
here :-)

> > WHAT MIGHT BREAK
> >
> > Code that currently works but will break with this change has two
> > properties:
> >
> > 1. It relies on the asymmetry in foldr, zipWith, or zip to avoid running
> > into bottom.
> > 2. foldr2/right does not fire, either because the second list is not a good
> > producer or because GHC applies the foldr2/left rule instead.
> >
> > That is, most of the code that this change will break is fragile under the
> > current scheme.
> >
> > DISCUSSION PERIOD
> >
> > Standard two weeks.

Given that nobody complained about the standard-non-conformance so far I
think having a symmetric zip where the RULES are semantics-preserving is
more useful than strictly following the report. But I could be convinced
otherwise.


David, I think you can go ahead and prepare a patch. People can still
speak up before (and even after) it is applied if they disagree.

Greetings,
Joachim

-- 
Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140908/e8a89b94/attachment.sig>


More information about the Libraries mailing list