title: Why can't I convert this type into a generic one?
body: <pre><code>def linearInterpolation(weights: Seq[Double], points: Seq[Seq[Double]]) : Seq[T] = {
  
    weights.zip(points).map(
      weight_point =&gt; weight_point._2.map(coordinate =&gt; weight_point._1 * coordinate)
    ).reduce((point_a : Seq[Double], point_b : Seq[Double]) =&gt; point_a.zip(point_b).map(coordinate_points =&gt; (coordinate_points._1 + coordinate_points._2).asInstanceOf[T]))
  
  }
  </code></pre>
  
  <p>In this code, I'm trying to convert the type of the return, a <code>Seq[Double]</code>, to a <code>Seq[T]</code>. At the execution of the call, <code>T</code> could be e.g. <code>Double</code> or <code>Int</code>.</p>
  
  <p>This conversion should be realized thanks to <code>.asInstanceOf[T]</code>.</p>
  
  <h1>Errors</h1>
  
  <p>The code compiles.</p>
  
  <p>But if I execute it, I get the following errors :</p>
  
  <blockquote>
    <p>Error:(25, 61) type mismatch;
     found   : (Seq[Double], Seq[Double]) => Seq[T]
     required: (Seq[Any], Seq[Any]) => Seq[Any]
        ).reduce((point_a : Seq[Double], point_b : Seq[Double]) => point_a.zip(point_b).map(coordinate_points => (coordinate_points._1 + coordinate_points._2).asInstanceOf[T]))</p>
    
    <p>Error:(25, 13) type mismatch;
     found   : Seq[Any]
     required: Seq[T]
        ).reduce((point_a : Seq[Double], point_b : Seq[Double]) => point_a.zip(point_b).map(coordinate_points => (coordinate_points._1 + coordinate_points._2).asInstanceOf[T]))</p>
  </blockquote>
  
  <h1>Question</h1>
  
  <p>Why does the execution fail ? How to achieve this conversion from a <code>Seq[Double]</code> to a <code>Seq[T]</code> ?</p>