再帰関数には @tailrec アノテーションを

再帰関数を書くときのメモ。

再帰関数には @tailrec アノテーションを - イトウ アスカ blog

Scala 2.8では、@scala.annotaiton.tailrecアノテーションが追加されたそうです。これを末尾再帰最適化を期待するメソッドにつけとくと、最適化されないパターンだったときにコンパイラがエラーを吐いてくれるそうです。

Scaladoc for scala.annotation.tailrec

A method annotation which verifies that the method will be compiled with tail call optimization. If it is present, the compiler will issue an error if the method cannot be optimized into a loop.