<div dir="ltr">Take a look <a href="http://bm380.user.srcf.net/cgi-bin/stepeval.cgi?expr=let+fix+f+%3D+f+%28fix+f%29%0D%0A++++fact+%3D+fix+%24+%5Cf+n+-%3E+if+n+%3D%3D+0+then+1+else+n+*+f+%28n+-+1%29%0D%0Ain+fact+4">here</a>.<div>The above webpage uses <a href="https://github.com/bmillwood/stepeval">stepval</a>, it can evaluate any expression step by step using equational reasoning.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 27 January 2015 at 11:54, Karl Voelker <span dir="ltr"><<a href="mailto:karl@karlv.net" target="_blank">karl@karlv.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>




<div><span class=""><div>On Mon, Jan 26, 2015, at 08:43 PM, Animesh Saxena wrote:<br></div>
<blockquote type="cite"><div>I stumbled across this example as a shiny way of explaining why Lazy eval matters....<br></div>
<div> </div>
<div><div>    fact = fix $ \f n -> if n == 0 then 1 else n * f (n-1)<br></div>
</div>
<div>fix f = f (fix f)<br></div>
<div> </div>
<div>With lazy eval, I get <br></div>
<div> </div>
<div>fact 4 = fix $ \f 4 (......)<br></div>
</blockquote><div> </div>
</span><div>Not quite. Let's go one step at a time:<br></div>
<div> </div>
<div>fact 4 = (fix $ \f n -> if n == 0 then 1 else n * f (n - 1)) 4<br></div>
<div> </div>
<div>Now we can bring in the definition of fix, substituting the argument to fix for all of the occurrences of f in the definition of fix. Notice that we can't substitute the 4 for n yet.<br></div>
<div> </div>
<div>fact 4 = ((\f n -> if n == 0 then 1 else n * f (n - 1)) (fix $ \f n -> if n == 0 then 1 else n * f (n - 1))) 4<br></div>
<div> </div>
<div>I think if you are very patient and methodical about performing the substitutions (and writing them out fully - no dot-dot-dot), then you'll figure out how it all works.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888">
<div> </div>
<div>-Karl<br></div>
<div> </div>
</font></span></div>

<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>