<div dir="ltr"><div class="gmail_default" style="font-size:small">hi, everyone,<br><br></div><div class="gmail_default" style="font-size:small">I&#39;m learning haskell by reading the book &lt;&lt;Yet Another Haskell Tutorial&gt;&gt;, and I encounter a problem when comes to the contiuation passing style. The book gives a  cps fold like:<br>

<br>cfold’ f z [] = z<br>cfold’ f z (x:xs) = f x z (\y -&gt; cfold’ f y xs)<br><br>and gives the test result:<br><br>CPS&gt; cfold (+) 0 [1,2,3,4]<br>10<br>CPS&gt; cfold (:) [] [1,2,3]<br>[1,2,3]<br><br></div><div class="gmail_default" style="font-size:small">

but, when I try to test this, I find there is a problem, the ghci gives:<br><br>-----------------------------------------------------------------------<br>*Main&gt; cfold (+) 0 []<br><br>&lt;interactive&gt;:8:7:<br>    Occurs check: cannot construct the infinite type:<br>

      t10 = (t10 -&gt; t10) -&gt; t10<br>    Expected type: t10 -&gt; t10 -&gt; (t10 -&gt; t10) -&gt; t10<br>      Actual type: t10 -&gt; t10 -&gt; t10<br>    In the first argument of `cfold&#39;, namely `(+)&#39;<br>    In the expression: cfold (+) 0 []<br>

    In an equation for `it&#39;: it = cfold (+) 0 []<br>------------------------------------------------------------------------<br><br></div><div class="gmail_default" style="font-size:small">It makes sense to me, so I change the definition of cps to something like this:<br>

<br>cfold f z [] = z<br>cfold f z (x:xs) = (\y -&gt; cfold f y xs) (f x z)<br><br></div><div class="gmail_default" style="font-size:small">And it works fine:<br><br>*Main&gt; cfold (+) 0 [1,2,3]<br>6<br><br></div><div class="gmail_default" style="font-size:small">

So my question comes, is it a bug in the book or something I miss here?<br><br><br><br></div><div class="gmail_default" style="font-size:small">Regards!<br>-<br></div><div class="gmail_default" style="font-size:small">wudeng<br>

</div><div class="gmail_default" style="font-size:small"><br></div></div>