錯誤我有一個簡單的方法來建立一個樹:尾調用優化的投擲簡單的功能
@tailrec final def buildTree (X:DenseMatrix[Double], Y:DenseVector[Double], minBucket:Int):Node = {
// Get the split variable, split point and data
val (splitVar, splitPoint, leftX, leftY, rightX, rightY) = chooseSplit(X, Y, minBucket);
// If we couldn't find a split, then we have a leaf
if(splitVar == Double.NegativeInfinity){
new Node(Y)
}else{
// Otherwise recursively build the children and create yourself as a vertex
val left = buildTree(leftX, leftY, minBucket)
val right = buildTree(rightX, rightY, minBucket)
new Node(Y, splitVar, splitPoint, left, right)
}
然而,當我去編譯,我得到: could not optimize @tailrec annotated method buildTree: it contains a recursive call not in tail position
我做的事情像OCaml一樣沒有任何問題。有沒有解決這個問題的方法?
請參閱[這個問題]的答案(http://stackoverflow.com/questions/4785502/why-wont-the-scala-compiler-apply-tail-call-optimization-unless-a-method-is-鰭)。 – dfan