<div dir="ltr">Regarding implementing last with foldl, this is exactly the time you would not use foldl' but would only use foldl. Implementing last with foldl' will force all of the elements of the list on the way to returning the last element.<div><br></div><div>Best regards,</div><div>Eric Mertens</div><div>glguy</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 10, 2016 at 10:40 AM Bart Massey <<a href="mailto:bart.massey@gmail.com">bart.massey@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I guess by "packages may have come to rely on it" you mean some situation where performance is improved by the implicit strictness? It's hard for me to imagine relying on getting bottom instead of a result. However, it's also hard for me to imagine relying on foldl' forcing the initial value in the case of folding on an empty list, and in non-empty list cases the folding function is likely going to be strict on the accumulator anyhow. (The last example I gave is an exception to that rule.)<div><br></div><div>As to the lack of documentation of laziness, my understanding is that functions in Data.List are expected to be lazy anywhere that their strictness is not explicitly documented? I don't know if there's actually language like that in any of the Reports, but the Haddock for Data.List says, among other things:</div><div><span style="line-height:18.2px"><br></span></div><div><div><span style="line-height:18.2px">> For a general</span><span style="line-height:18.2px"> </span><code style="margin:0px;padding:0px;line-height:16.12px"><a href="https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Foldable.html#t:Foldable" style="color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none" target="_blank">Foldable</a></code><span style="line-height:18.2px"> </span><span style="line-height:18.2px">structure this should be semantically identical to,</span><br></div><div><pre style="margin-top:0.8em;margin-bottom:0.8em;padding:0.25em;line-height:16.12px;overflow:auto;border-bottom-width:0.25em;border-bottom-style:solid;border-bottom-color:white;background-image:initial;background-color:rgb(229,237,244);background-position:initial;background-repeat:initial">foldl f z = <code style="margin:0px;padding:0px;line-height:16.12px"><a href="https://hackage.haskell.org/package/base-4.9.0.0/docs/GHC-OldList.html#v:foldl-39-" style="color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none" target="_blank">foldl'</a></code> f z . <code style="margin:0px;padding:0px;line-height:16.12px"><a href="https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Foldable.html#v:toList" style="color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none" target="_blank">toList</a></code></pre></div></div><div><div><span style="line-height:18.2px">which doesn't seem to be actually the case right now, but does seem to be desirable. (Is the prime on the wrong side here? This seems backward to me, but I'm easily confused.)</span></div></div><div><span style="line-height:18.2px"><br></span></div><div>Anyhow, I'll be disappointed if it remains no longer viable to write  last = foldl' (flip const) undefined  as I did above. It makes the language harder to teach, and is nonintuitive to me.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 10, 2016 at 9:35 AM David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I would certainly have agreed back when 4.8 was in development. This was undoubtedly a breaking change. The fact that it's now been out for some time muddies the waters. So does the fact that the strictness has never been documented. It seems likely that most packages relying on the old behavior have been updated, and it's possible that some may have come to rely on it. I see this unfortunate situation as something of an opportunity to take a fresh look and decide what we want.</p>
<p dir="ltr">On the pro-revert side,</p>
<p dir="ltr">foldl'new f b xs = b `seq` foldl'old f b xs</p>
<p dir="ltr">which seems considerably less challenging than implementing the lazy version from scratch with the built-in GHC magic. But there could be times when that leads to some efficiency problem.</p>
<div class="gmail_quote">On Jun 10, 2016 12:10 PM, "Bart Massey" <<a href="mailto:bart.massey@gmail.com" target="_blank">bart.massey@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">-1 on retaining this. Part of the implied contract of Data.List is that all functions be as lazy as possible. Besides, a change that potentially breaks old programs that use foldl' seems like a bad idea unless there's a really strong reason for it. I don't have an existing example offhand, but it seems at least possible that something like<div><br></div><div>    last = foldl' (flip const) undefined</div><div><br></div><div>is out there...</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 10, 2016 at 5:29 AM David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">The semantics of foldl' for lists were changed between base 4.7 and base 4.8. Specifically, foldl' became strict in the initial value of its accumulator. I opened <a href="http://ghc.haskell.org/trac/ghc/ticket/12173" target="_blank">http://ghc.haskell.org/trac/ghc/ticket/12173</a> to report this. The change was entirely accidental, according to Joachim Breitner. However, Duncan Coutts indicated he is pleased with the change. I don't personally have a dog in this race, but I feel very strongly about three things:</p>
<p dir="ltr">1. The strictness should be fully documented, both in Haddock and the next Haskell Report (the Haskell 2010 Report does not go into sufficient detail to support either choice).</p>
<p dir="ltr">2. There should be *one* meaning of foldl' in base. Thus the default Foldable instance should match the ones for lists and arrays.</p>
<p dir="ltr">3. The containers package should be consistent with base in this regard.</p>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">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-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "haskell-core-libraries" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:haskell-core-libraries+unsubscribe@googlegroups.com" target="_blank">haskell-core-libraries+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div>