私はかなり単純な末尾再帰関数であると信じているものを持っています。しかし、そうではないと@tailrec
教えてくれます。
@tailrec
def _next(continue : String, current : List[Long], first : Boolean ) : Stream[Long] = {
current match {
case head :: tail => head #:: _next(continue, tail, false) //this line breaks tailrec
case Nil if first => empty
case _ => {
val (nc, nl) = getIds(continue)
_next(nc, nl, true)
}
}
}
それは私に
[error] could not optimize @tailrec annotated method _next: it contains a recursive call not in tail position
[error] case head :: tail => head #:: _next(continue, tail, false)
[error] ^
おそらく eclipse: から受け取った暗黙の通知に関係しています- Implicit conversions found: _next(continue, tail, false) => consWrapper(_next(continue, tail, false))
が、残念ながら、それは問題の解決には役立っていません。
どうすればこれを修正できますか? また、ブラウニー ポイントの場合、これが末尾再帰になるとどこで間違ったのでしょうか?