On Fri, Mar 6, 2009 at 1:48 AM, Daryoush Mehrtash <dmehrtash@gmail.com> wrote:
Question: Do I need to worry about space leak if I am using the fix to instead of the "let"?
Thanks
Daryoush2009/3/5 Luke Palmer <lrpalmer@gmail.com>
On Thu, Mar 5, 2009 at 6:27 PM, Donn Cave <donn@avvanta.com> wrote:
Quoth Jonathan Cast <jonathanccast@fastmail.fm>:
Would you mind presenting the better style argument? To me, the
> You can certainly use let:
>
> reader <- forkIO $ let loop = do
> (nr', line) <- readChan chan'
> when (nr /= nr') $ hPutStrLn hdl line
> loop
> in loop
>
> But the version with fix is clearer (at least to people who have fix in
> their vocabulary) and arguably better style.
above could not be clearer, so it seems like the version with fix
could be only as clear, at best.I like using fix when it's simple rather than let, because it tells me the purpose of the binding. eg., when I seelet foo = ...Where ... is fairly long, I'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't know what. Whereas with:fix $ \foo -> ...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.I know that it's a simple matter of scanning to the corresponding "in", but let can be used for a lot of things, where as fix $ \foo is basically only for simple knot-tying. Now, that doesn'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.Luke_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe