
voigt:
Donald Bruce Stewart wrote:
harald.rotter:
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).
Any hints are appreciated.
So actually, I suppose it is useful for small, anonymous recursive definitions.
It also exposes the recursive computation structure for direct manipulation, enabling one to perform certain program transformations/refactorings. Search for "fixpoint fusion" and "fixed point promotion". While one might say: that's the business of a compiler, actually existing ones are not very sophisticated in that regard, so one might want to do such transformations "by hand"...
Oh, excellent point. Just as naming particular loop structures (such as 'map' or 'unfoldr') enable more precise optimisations, such as fusion, so naming recursive functions saves the compiler some work discovering the name. -- Don