[Haskell-cafe] do you have to use fix with forkio?
lrpalmer at gmail.com
Thu Mar 5 20:33:29 EST 2009
On Thu, Mar 5, 2009 at 6:27 PM, Donn Cave <donn at avvanta.com> wrote:
> Quoth Jonathan Cast <jonathanccast at fastmail.fm>:
> > 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.
> Would you mind presenting the better style argument? To me, the
> 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 see
let 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe