<div class="gmail_quote">On Thu, Mar 5, 2009 at 6:27 PM, Donn Cave <span dir="ltr">&lt;<a href="mailto:donn@avvanta.com">donn@avvanta.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Quoth Jonathan Cast &lt;<a href="mailto:jonathanccast@fastmail.fm">jonathanccast@fastmail.fm</a>&gt;:<br>
<div class="im"><br>
&gt; You can certainly use let:<br>
&gt;<br>
&gt;   reader &lt;- forkIO $ let loop = do<br>
&gt;       (nr&#39;, line) &lt;- readChan chan&#39;<br>
&gt;       when (nr /= nr&#39;) $ hPutStrLn hdl line<br>
&gt;       loop<br>
&gt;     in loop<br>
&gt;<br>
&gt; But the version with fix is clearer (at least to people who have fix in<br>
&gt; their vocabulary) and arguably better style.<br>
<br>
</div>Would you mind presenting the better style argument?  To me, the<br>
above could not be clearer, so it seems like the version with fix<br>
could be only as clear, at best.</blockquote><div><br></div><div>I like using fix when it&#39;s simple rather than let, because it tells me the purpose of the binding.  eg., when I see</div><div><br></div><div>    let foo = ...</div>
<div><br></div><div>Where ... is fairly long, I&#39;m not sure what the purpose of foo is, or what its role is in the final computation.  It may not be used at all, or passed to some modifier function, or I don&#39;t know what.  Whereas with:</div>
<div><br></div><div>   fix $ \foo -&gt; ...</div><div><br></div><div>I know that whatever ... is, it is what is returne, and the purpose of foo is to use that return value in the expression itself.</div><div><br></div><div>
I know that it&#39;s a simple matter of scanning to the corresponding &quot;in&quot;, but let can be used for a lot of things, where as fix $ \foo is basically only for simple knot-tying.  Now, that doesn&#39;t say anything about the use of fix without an argument (passed to an HOF) or with a tuple as an argument or many other cases, which my brain has not chunked nearly as effectively.  I think fix is best with a single, named argument.</div>
<div><br></div><div>Luke</div></div>