<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Indeed, and I initially went to suggest a `foldMap'`-based
      implementation to keep with the current implementation of many
      Foldable functions that are based on `foldMap` rather than a raw
      `fold`.<br>
    </p>
    <div class="moz-cite-prefix">On 18/10/2020 22:04, Oleg Grenrus
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:035231ea-7187-f096-d5bc-29ffe752d41d@iki.fi">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      For the sake of bigger audience I didn't bother mentioning #.
      which is a coercion helper. It's essentially better (.) when the
      first argument is newtype constructor (i.e. coerce).<br>
      <br>
      So with Option A (strict):<br>
      <br>
          sum = getSum #. foldMap' Sum<br>
      <br>
      Or Option B (lazy)<br>
      <br>
          sum = getSum #. foldMap Sum<br>
      <br>
      ---<br>
      <br>
      There is also third option, Option C:<br>
      <br>
          sum  = foldr  (+) 0<br>
          sum' = foldl' (+) 0<br>
      <br>
      I don't think this is worthwhile, but it is an option.<br>
      (to rehash, I don't consider maintaining status quo to be an
      option at all).<br>
      <br>
      - Oleg
      <div class="moz-cite-prefix">On 18.10.2020 22.54, Vanessa McHale
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:ace346e5-c6d1-0cb3-7262-111d15b10b09@gmail.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <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" 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" 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>
    <pre class="moz-signature" cols="72">-- 
Hécate ✨
IRC: Uniaika
WWW: <a class="moz-txt-link-freetext" href="https://glitchbra.in">https://glitchbra.in</a>
RUN: BSD</pre>
  </body>
</html>