<div dir="ltr"><div><div>Dear all,<br><br><a href="https://github.com/nushio3/practice/blob/master/recursion-schemes/FibTest.hs">https://github.com/nushio3/practice/blob/master/recursion-schemes/FibTest.hs</a><br><br></div>

After learning fix-point operators, I found an answer by myself.<br><br>```<br><pre><div class="" id="LC56"><span class="">fibBase</span> <span class="">::</span> <span class="">(</span><span class="">Integer</span> <span class="">-&gt;</span> <span class="">Integer</span><span class="">)</span> <span class="">-&gt;</span> <span class="">Integer</span> <span class="">-&gt;</span> <span class="">Integer</span></div>

<div class="" id="LC57"><span class="">fibBase</span> <span class="">fib</span> <span class="">n</span></div><div class="" id="LC58">  <span class="">|</span> <span class="">n</span> <span class="">&lt;=</span> <span class="">1</span>    <span class="">=</span> <span class="">1</span></div>

<div class="" id="LC59">  <span class="">|</span> <span class="">otherwise</span> <span class="">=</span> <span class="">fib</span> <span class="">(</span><span class="">n</span><span class="">-</span><span class="">1</span><span class="">)</span> <span class="">+</span> <span class="">fib</span> <span class="">(</span><span class="">n</span><span class="">-</span><span class="">2</span><span class="">)</span></div>

<div class="" id="LC60"><br></div><div class="" id="LC61"><span class="">fibWithFix</span> <span class="">::</span> <span class="">Integer</span> <span class="">-&gt;</span> <span class="">Integer</span></div><div class="" id="LC62">

<span class="">fibWithFix</span> <span class="">=</span> <span class="">fix</span> <span class="">fibBase<br>```<br><br></span></div></pre></div>I can say `fibBase` is free of recursion, despite the facts that apparently it uses a name `fib` on RHS which it binds on the LHS, and that the entire structure seems very similar to the recursive version of `fib` .<br>

<div><div><div><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/6/16 Takayuki Muranushi <span dir="ltr">&lt;<a href="mailto:muranushi@gmail.com" target="_blank">muranushi@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In an attempt to understand why cata- and anamorphisms are considered so important, I found multiple implications that you can write any recursive functions in terms of nonrecursive functions and ana, cata (am I right here?) so I&#39;m trying to practice the rewrite by a few functions. I&#39;m following a recipe found here:<br>


<div><br><a href="http://lambda-the-ultimate.org/node/4290" target="_blank">http://lambda-the-ultimate.org/node/4290</a><br clear="all"><br>~~~<br>Given a function that recurses on itself, do a partial CPS transform so 
that it only ever recurses on itself with tail calls.  Then, convert the
 recursive calls to codata returns, so that the function either returns 
TheAnswer or StillWorking with enough parameters to describe the 
recursive call / continuation state.  This codata can be built with an 
unfold and can be collapsed back down to the final answer with a fold.<br>~~~<br><br><br><a href="https://github.com/nushio3/practice/blob/master/lens/banana/CollatzTest.hs" target="_blank">https://github.com/nushio3/practice/blob/master/lens/banana/CollatzTest.hs</a><br>


<a href="https://github.com/nushio3/practice/blob/master/lens/banana/FibTest.hs" target="_blank">https://github.com/nushio3/practice/blob/master/lens/banana/FibTest.hs</a><br><br></div><div>I find it difficult to understand the terminology, and the above attempts are only halfway done. I guess ( 
TheAnswer or StillWorking ) structure is the one found in iteratee/enumeratee. But I don&#39;t know how to &quot;build a codata with unfold.&quot; <br><br></div><div>I&#39;d appreciate any advice.<br></div><div><br></div>


<div>Best,<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>-- <br>Takayuki MURANUSHI<br>The Hakubi Center for Advanced Research, Kyoto University<br><a href="http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html" target="_blank">http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html</a>
</div></font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br>Takayuki MURANUSHI<br>The Hakubi Center for Advanced Research, Kyoto University<br><a href="http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html" target="_blank">http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html</a>
</div>