title: default value for functions in parameters in Scala
body: <p>I was learning and experimenting with Scala. I wanted to implement a function with generic type, which takes a function as a parameter and provides a default implementation of that function..</p>
  
  <p>Now when I try it without the generic type, it works :</p>
  
  <pre><code>def defaultParamFunc(z: Int, y: Int)(f: (Int, Int) =&gt; Int = (v1: Int,v2: Int) =&gt; { v1 + v2 }) : Int = {
    val ans = f(z,y)
    println("ans : " + ans)
    ans
  }
  </code></pre>
  
  <p>this doesn't give any error</p>
  
  <p>but when I try the same with generic type, </p>
  
  <pre><code>def defaultParamFunc[B](z: B, y: B)(f: (B, B) =&gt; B = (v1: B,v2: B) =&gt; { v1 + v2 }) = {
    val ans = f(z,y)
    println("ans : " + ans)
    ans
  }
  </code></pre>
  
  <p>I get the error :</p>
  
  <pre><code>[error]  found   : B
  [error]  required: String
  [error]  def defaultParamFunc[B](z: B, y: B)(f: (B, B) =&gt; B = (v1: B,v2: B) =&gt; { v1 + v2 }) = {
  [error]                                                                               ^
  </code></pre>
  
  <p>Is the error because the compiler doesn't know if B type will be addable ? because when I just return v1 or v2 instead of v1 + v2, it works..</p>
  
  <pre><code>def defaultParamFunc[B](z: B, y: B)(f: (B, B) =&gt; B = (v1: B,v2: B) =&gt; { v1 }) = {
    val ans = f(z,y)
    println("ans : " + ans)
    ans
  }
  </code></pre>
  
  <p>If so, How to specify that the type given must be Numeric ? I tried replacing B with B : Numeric but still gives the same error</p>