category-theory-presentation/categories/30_How/300_Catamorphisms/030_morphism_fold_generalization.html
2013-02-28 16:49:12 +01:00

14 lines
815 B
HTML

<h2 id="κατα-morphism-fold-generalization">κατα-morphism: fold generalization</h2>
<p><code>acc</code> type of the &quot;accumulator&quot;:<br /><code>fold :: (acc -&gt; a -&gt; acc) -&gt; acc -&gt; [a] -&gt; acc</code></p>
<p>Idea: put the accumulated value inside the type.</p>
<pre class="haskell"><code>-- Equivalent to fold (+1) 0 "cata"
(Cons 'c' (Cons 'a' (Cons 't' (Cons 'a' Nil))))
(Cons 'c' (Cons 'a' (Cons 't' (Cons 'a' <span style="border: solid 1px;">0</span>))))
(Cons 'c' (Cons 'a' (Cons 't' <span style="border: solid 1px;">1</span>)))
(Cons 'c' (Cons 'a' <span style="border: solid 1px;">2</span>))
(Cons 'c' <span style="border: solid 1px;">3</span>)
<span style="border: solid 1px;">4</span></code></pre>
<p>But where are all the informations? <code>(+1)</code> and <code>0</code>?</p>