Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the compiler looks for an <code>implicit (Double, Double) =&gt; Double</code> in implicit scope, either there is exactly one with higher priority and it will choose that one both times, or there is not (either there is none at all in implicit scope, or more than one with the highest priority) and there will be an error for lack of an implicit value. </p> <p>If you want to distinguish, you may have two different types, both extending Function2[Double, Double, Double]. For instance</p> <pre><code>trait Addition extends Function[Double, Double, Double] trait Multiplication extends Function[Double, Double, Double] class Example(implicit addition: Addition, implicit multiplication: Multiplication) </code></pre> <p>This may be ok it makes sense to choose both operation independently. If the two choices need to be conistent, it might make more sense to have just one trait with both operation</p> <pre><code>trait Ring { def add(x: Double, y: Double): Double def mult(x: Double, y: Double): Double } // or `case class Ring( // addition: (Double, Double) =&gt; Double, // multiplication: (Double, Double) =&gt; Double) class Example(implicit ring: Ring) </code></pre> <p>Finally, all of this is useful only if you get the proper operations in implicit scope "naturally". If you have to do make them implicit each time you create an example, like in </p> <pre><code>implicit val addition = ... implicit val multiplication = new Example </code></pre> <p>you could as well be explicit .</p> <p>Also, if most of calls are expected to work with the same value, and you just want to change a few of them, you might rather go for arguments with default values</p> <pre><code>class Example(doSomething1 : (Double, Double) =&gt; Double = &lt;default value&gt;, doSomething2 ...) </code></pre> <p>You may even have both of it, an implicit argument with the default value. If you do that, the default value is used when no implicit is found. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload