<div dir="ltr">The current intent based on the ghc ticket traffic is to switch the implementation to foldl1 for the next release as a stopgap, but leave the door open to do something smarter in the future. <div><div><br></div><div>The current foldr1 implementation is simply never a win, and a monoidal version devolves to a right fold for lists with the same bad behavior. <br><br>If we later on figure out a way to efficiently exploit a strict monoidal accumulator for monoids that don't benefit from short-circuiting then a number of current Foldable combinators could benefit including this one, so we definitely want to leave the door open to doing things better in the future, but for now the left fold is an easy improvement over the status quo.<div><br></div><div>-Edward</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 25, 2017 at 6:50 PM, David Laing <span dir="ltr"><<a href="mailto:dave.laing.80@gmail.com" target="_blank">dave.laing.80@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi all,<br><br></div><div>I'm proposing that the implementations of minimumBy and maximumBy be changed from using foldl1 to foldr1.</div><div><br></div><div>I found this in a GHC trac ticket[0] labelled 'Newcomer' that has more details / discussion on that.<br><br></div><div>The points that stand out to me are:<br></div><div>- the Haskell report says that those methods should be implemented in terms of foldl1 (although as instance methods of Foldable there might be some wiggle room there)<br></div><div>- it helps solves a space leak (which at first glance feels like it might be a more common problem than the options that foldl1 removes)<br></div><div>- from the discussion on the ticket, it seemed to be an agreeable middle ground<br></div><div><br>As a side note: there have been a few proposals in the past to switch these functions to use foldl', which seemed to have stalled.  I don't know what the etiquette is around bringing up minor variations on old proposals again, so I apologise if I've breached some kind of protocol here.  <br><br>Although I guess I've already breached one protocol by pushing a  patch to Phabricator for review without getting sign-off from the Core Libraries Committee, so at least I'm being even handed with my clumsiness :)<br><br></div>Cheers,<br><br></div>Dave<br><div><div><div><br>[0] <a href="https://ghc.haskell.org/trac/ghc/ticket/10830" target="_blank">https://ghc.haskell.org/trac/<wbr>ghc/ticket/10830</a><br><br></div></div></div></div>
<br>______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>