I understand your concerns about modifying the current ideology, it&#39;s fair enough.<br>Actually I&#39;m myself more in favor of adding strict couterparts, and export them conjointly, to support both the mathematical roots and the performances of the operations that are done most of time (Which kind of numbers do developers work with more often? Regular Ints and Doubles or Peano lazy numbers?)<br>

<br><br><div class="gmail_quote">2012/5/23 wren ng thornton <span dir="ltr">&lt;<a href="mailto:wren@freegeek.org" target="_blank">wren@freegeek.org</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On 5/21/12 10:51 AM, Yves Parès wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I do think we have the opposite problem, however, in much Haskell code --<br>
</blockquote>
people are using the clean, obviously correct, but inefficient code even in<br>
standard library functions that really should be optimized like crazy!<br>
<br>
And even before optimizing &quot;like crazy&quot;, I think the functions that are<br>
&quot;more often&quot; good should be emphasized: Prelude should export foldl&#39;<br>
together with/instead of foldl, sum should have its sum&#39; counterpart (or<br>
even be rewritten to use foldl&#39;), and so on...<br>
It baffles me that functions that are said to be more efficient in the<br>
majority of cases are not the default.<br>
</blockquote>
<br></div>
Part of this is due to legacy and the Haskell Report. For example, the definition of sum is specified by the Report. And unfortunately there exist (rare) cases where the semantics of sum and sum&#39; differ: namely when the type supports lazy addition (e.g., Peano numbers) and therefore can return a partial answer to an infinite summation.<br>


<br>
That said, the GHC philosophy in most of these cases has been to:<br>
<br>
(a) use their own definitions with a CPP flag USE_REPORT_PRELUDE in case you *really* want the Report&#39;s definition[1], and<br>
<br>
(b) to &quot;secretly&quot; replace foldl by foldl&#39; in cases where it can determine the function argument to be strict (and therefore that the change doesn&#39;t alter the semantics).<br>
<br>
That doesn&#39;t fix everything, and it&#39;s no justification for not having the newer Reports give more sane definitions, but it&#39;s better than nothing.<br>
<br>
Part of the issue re fixing the Report is that there&#39;s a tension between correctness and expediency, as well as between different notions of &quot;correctness&quot;. By and large, Haskell has managed to stay out of theoretical arguments about choosing what &quot;correct&quot; means when it is still controversial in mathematics. (Whence many of the complaints about the non-mathematical nature of the numeric type classes.) But which of the foldr vs foldl vs foldl&#39; definitions of summation is the &quot;correct&quot; definition? Mathematically, infinite summations should be allowed, and summations of infinite quantities should be allowed. However, pragmatically, infinite summations are of a different nature than finite summations; e.g., when they converge it&#39;d be nice to evaluate them in finite time. So on the one hand, a naive view of &quot;correctness&quot; suggests that we ought to allow these summations as just more of the same; but on the other hand, an alternative notion of &quot;correctness&quot; suggests that while infinite sums and sums of infinites should be handled, they should be handled by different means than traditional finite sums of finite values.<br>


<br>
The foldl&#39; definition of summation only allows finite summations of finite[2] values; the foldl definition only allows finite summations, but they can be summations of infinite values; the foldr definition allows both infinite values and infinitely many summands, though it&#39;s not especially useful for handling infinite summations[3]. We can probably exclude foldr with all fairness, and tell folks to handle infinite summations in another way. But between foldl and foldl&#39; there&#39;s (room for) a lot more debate about which should be blessed by the Prelude. Do we want to support lazy numbers out of the box, or do we want to support performance for strict numbers out of the box? While there&#39;s been a growing strictification of Haskell for performance reasons, do recall that laziness was one of the initial reasons for defining Haskell in the first place. Hence the old Report&#39;s definition. The role of Haskell as a research engine has moved on since then, but the decision to codify that is still non-trivial.<br>


<br>
<br>
[1] <a href="http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/src/Data-List.html#sum" target="_blank">http://hackage.haskell.org/<u></u>packages/archive/base/4.5.0.0/<u></u>doc/html/src/Data-List.html#<u></u>sum</a><br>


<br>
[2] For the purpose of discussion, I&#39;m considering the Float and Double values for infinities to be &quot;finite&quot;, because they are identical to the finite values with respect to strictness and size of representation.<br>


<br>
[3] It could take infinitely long to return, even for types which allow lazily returning partial values. For example,<br>
<br>
    data Peano = Z | S Peano<br>
    instance Num Peano where ...<br>
<br>
    zeros = Z : zeros<br>
<br>
    -- Has to traverse the whole list, just in case there&#39;s a (S _) in<br>
    -- there somewhere, before it knows whether to return Z or (S _).<br>
    main = print (foldr (+) Z zeros)<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Live well,<br>
~wren</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>