<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>It's <br>
</p>
<p>sum = getSum #. foldMap Sum<br>
<br>
in base.</p>
<div class="moz-cite-prefix">On 10/18/20 2:49 PM, Oleg Grenrus
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:cbe97c20-f365-a72e-f6e0-b00c5280f0a2@iki.fi">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>The problem is the current definition of sum for lists which
uses foldl, i.e non-strict left fold</p>
<p> sum = foldl (+) 0<br>
<br>
It's utterly broken. Either we should change it to foldl' to
work on some types where addition is strict, Option A:<br>
<br>
sum = foldl' (+) 0<br>
<br>
or alternatively (to make people using lazy accumulator types),
Option B:<br>
<br>
sum = foldr (+) 0<br>
<br>
The current state is no good for anyone or anything.<br>
<br>
---<br>
<br>
Related issue which Hecate didn't clearly mention, is that
Foldable class default implementation has<br>
<br>
class Foldable f where<br>
...<br>
sum = getSum . foldMap Sum -- this is "good" lazy
definition<br>
<br>
If we select option A, then I argue that for consistency the
default `Foldable.sum` should be<br>
<br>
sum = getSum . foldMap' Sum -- strict foldMap'<br>
<br>
If we select option B, Foldable definition doesn't need to be
changed.<br>
<br>
---<br>
<br>
I repeat, using non-strict left fold, foldl, for sum and product
is not good for anything.<br>
Either foldr or foldl'.<br>
<br>
I have no strong preference. Current state is unacceptable.<br>
<br>
- Oleg<br>
</p>
<div class="moz-cite-prefix">On 18.10.2020 22.24, Henning
Thielemann wrote:<br>
</div>
<blockquote type="cite"
cite="mid:alpine.DEB.2.20.2010182121500.5252@sputnik"> <br>
On Sun, 18 Oct 2020, Hécate wrote: <br>
<br>
<blockquote type="cite">In conclusion, leaving things to the
optimiser that could be trivially made fast every time seems
needlessly risky. <br>
</blockquote>
<br>
`seq` is still a hack. A strict 'sum' and 'product' would still
fail on a lazy accumulator type, say a lazy pair type. If at
all, sum and product should be deepseq-strict. So currently,
letting the optimiser make a lazy sum strict is still the
smaller hack.<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Libraries mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libraries@haskell.org" moz-do-not-send="true">Libraries@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" moz-do-not-send="true">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a>
</pre>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Libraries mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libraries@haskell.org">Libraries@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a>
</pre>
</blockquote>
</body>
</html>