title: Recursive List concatenation
body: <p>I have the following function that returns a list of distances between the elements of a list of integers:</p>
  
  <pre><code>def dists(l: List[Int]) = {
    //@annotation.tailrec
    def recurse(from: Int, rest: List[Int]): List[Int] = rest match {
      case Nil =&gt; Nil
      case to :: tail =&gt; to - from :: recurse(to, tail)
    }
  
    l match {
      case first :: second :: _ =&gt; recurse(first, l.tail)
      case _ =&gt; Nil
    }
  }
  </code></pre>
  
  <p>The <code>::</code> prevents me from using the <code>@tailrec</code>annotation although it seems that the call to <code>recurse</code> is in tail position.</p>
  
  <p>Is there a <code>@tailrec</code> compatible way to do the concatenation?</p>
  
  <p>I could use an accumulator but then I would have to inverse the input or the output, right?</p>
  
  <p>Edit: I am especially interested in the recursive approach. My concrete use case is a bit more complicated in that one call to <code>recurse</code> could add several items to the result list:</p>
  
  <pre><code>=&gt; item1 :: item2:: recurse(...)
  </code></pre>
  
  <p>The distance function is just an example to demonstrate the problem.</p>