list match { case End => 0 case Pair(hd, tl) => hd + sum(tl) } // <console>:18: error: could not optimize @tailrec annotated method sum: it ... // def sum(list: IntList): Int = list match { // ^ @tailrec def sum(list: IntList, total: Int = 0): Int = list match { case End => total case Pair(hd, tl) => sum(tl, total + hd) } // sum: (list: IntList, total: Int)Int