<p dir="auto">Currently, the <code class="notranslate">sum</code> function use the element type (except for the boolean case) of the input array as result type. This is sometimes not a desirable choice:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function mysum(R, x)
    s = zero(R)
    for v in x; s += v; end
    return s
end

julia&gt; x = uint8(rand(1:10, 50));

julia&gt; sum(x)
0x0000000000000122

# to prevent overflow
julia&gt; mysum(Int, x)
290

julia&gt; a = rand(Float32, 10^6);

julia&gt; sum(float64(a)) - sum(a)
-0.018809685949236155

# to get higher accuracy
julia&gt; sum(float64(a)) - mysum(0.0, a)
1.1641532182693481e-10"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">mysum</span>(R, x)
    s <span class="pl-k">=</span> <span class="pl-c1">zero</span>(R)
    <span class="pl-k">for</span> v <span class="pl-k">in</span> x; s <span class="pl-k">+=</span> v; <span class="pl-k">end</span>
    <span class="pl-k">return</span> s
<span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> x <span class="pl-k">=</span> <span class="pl-c1">uint8</span>(<span class="pl-c1">rand</span>(<span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">10</span>, <span class="pl-c1">50</span>));

julia<span class="pl-k">&gt;</span> <span class="pl-c1">sum</span>(x)
<span class="pl-c1">0x0000000000000122</span>

<span class="pl-c"><span class="pl-c">#</span> to prevent overflow</span>
julia<span class="pl-k">&gt;</span> <span class="pl-c1">mysum</span>(Int, x)
<span class="pl-c1">290</span>

julia<span class="pl-k">&gt;</span> a <span class="pl-k">=</span> <span class="pl-c1">rand</span>(Float32, <span class="pl-c1">10</span><span class="pl-k">^</span><span class="pl-c1">6</span>);

julia<span class="pl-k">&gt;</span> <span class="pl-c1">sum</span>(<span class="pl-c1">float64</span>(a)) <span class="pl-k">-</span> <span class="pl-c1">sum</span>(a)
<span class="pl-k">-</span><span class="pl-c1">0.018809685949236155</span>

<span class="pl-c"><span class="pl-c">#</span> to get higher accuracy</span>
julia<span class="pl-k">&gt;</span> <span class="pl-c1">sum</span>(<span class="pl-c1">float64</span>(a)) <span class="pl-k">-</span> <span class="pl-c1">mysum</span>(<span class="pl-c1">0.0</span>, a)
<span class="pl-c1">1.1641532182693481e-10</span></pre></div>
<p dir="auto">My proposal is to add a method like <code class="notranslate">sum(R, x)</code> where <code class="notranslate">R</code> is the user-specifed type. This won't break any existing codes, but provide the user additional choices.</p>
<p dir="auto">Both the spec for <a href="https://github.github.com/gfm/#hard-line-breaks">Github Flavoured Markdown</a> and <a href="https://spec.commonmark.org/0.29/#hard-line-break" rel="nofollow">CommonMark</a> state:</p>
<blockquote>
<p dir="auto">A line break (not in a code span or HTML tag) that is preceded by two or more spaces and does not occur at the end of a block is parsed as a hard line break (rendered in HTML as a <br> tag):</p>
</blockquote>
<p dir="auto">But if you write such code in Julia, that new line is just replaced with a space; as if it were not preceded by two spaces in the source.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; md&quot;foo
       bar&quot;.content
1-element Vector{Any}:
 Markdown.Paragraph(Any[&quot;foo   bar&quot;])"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-s"><span class="pl-pds"><span class="pl-c1">md</span>"</span>foo</span>
<span class="pl-s">       bar<span class="pl-pds">"</span></span><span class="pl-k">.</span>content
<span class="pl-c1">1</span><span class="pl-k">-</span>element Vector{Any}<span class="pl-k">:</span>
 Markdown<span class="pl-k">.</span><span class="pl-c1">Paragraph</span>(Any[<span class="pl-s"><span class="pl-pds">"</span>foo   bar<span class="pl-pds">"</span></span>])</pre></div>
<p dir="auto">The correct output would be</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1-element Vector{Any}:
Markdown.Paragraph(Any[&quot;foo\nbar&quot;])"><pre class="notranslate"><code class="notranslate">1-element Vector{Any}:
Markdown.Paragraph(Any["foo\nbar"])
</code></pre></div>
<p dir="auto">This forces extra line breaks in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="778356984" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/39093" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/39093/hovercard" href="https://github.com/JuliaLang/julia/pull/39093">#39093</a> as there is no way to have a linebreak without inserting a full blank line (i.e. making two <code class="notranslate">Markdown.Paragraphs</code>)</p>