14 lines
815 B
HTML
14 lines
815 B
HTML
<h2 id="κατα-morphism-fold-generalization">κατα-morphism: fold generalization</h2>
|
|
<p><code>acc</code> type of the "accumulator":<br /><code>fold :: (acc -> a -> acc) -> acc -> [a] -> 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>
|