If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Thursday, November 26, 2009

Scala: Tail recursion

Looking back at our Fibonnaci examples the Scala compiler offers one big performance boost when using recursion. The only condition is that you use tail recursion. What this basically means is that the last expression in your recursive method is a call to itself.

Below follows a refactored recursive implementation which performs almost as fast as the non-recursive implementation.

No comments:

Post a Comment