[Haskell-cafe] advantages of using fix to define rcursive functions

Jonathan Cast jcast at ou.edu
Thu Jul 26 10:23:19 EDT 2007


On Thursday 26 July 2007, Harald ROTTER wrote:
> Hi,
>
> I read about the usage of "fix" to define recursive functions. Although I
> think that I understood how to use "fix", I still wonder what the
> advantages of "fix" are (as compared to the "conventional" approach to
> define recursive functions).

As others have said, it allows you to define anonymous recursive functions 
(not necessarily small!).  FPers have traditionally advocated using lots of 
small, named, top-level functions, but I think it's amazing how much more 
readable code becomes when some of those single-use functions are inlined.  
You can't inline a recursive function, but you can inline an application of 
fix.

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070726/03436fa9/attachment.bin


More information about the Haskell-Cafe mailing list