Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are thinking about partial application, I thought that this was only possible with <strong>multiple parameter lists</strong> (whereas you only have one):</p> <pre><code>def plus(x: Int)(y: Int) = x + y //x and y in different parameter lists val plus10 = plus(10) _ //_ indicates partial application println(plus10(2)) //prints 12 </code></pre> <p>Your example is interesting though as I was completely unaware of the syntax you describe and it appears you can have partial application with a single parameter list:</p> <pre><code>scala&gt; def plus2(x: Int, y: Int) = x + y plus2: (x: Int,y: Int)Int scala&gt; val anon = plus2(_,_) anon: (Int, Int) =&gt; Int = &lt;function2&gt; scala&gt; anon(3, 4) res1: Int = 7 </code></pre> <p>So the compiler can clearly infer the type <code>Int</code>!</p> <pre><code>scala&gt; val anon2 = plus2(20,_) &lt;console&gt;:5: error: missing parameter type for expanded function ((x$1) =&gt; plus2(20, x$1)) val anon2 = plus2(20,_) ^ </code></pre> <p>Hmmm, strange! I don't seem to be able to do partial application with a single parameter list. But then if I declare the type of the second parameter, I <em>can</em> have partial application!</p> <pre><code>scala&gt; val anon2 = plus2(20,_: Int) anon2: (Int) =&gt; Int = &lt;function1&gt; scala&gt; anon2(24) res2: Int = 44 </code></pre> <p><strong>EDIT</strong> - one thing I would observe is that it seems like the following two shortenings are equivalent, in which case it's a bit more obvious that this is not a "partial application" but more like a "function pointer"</p> <pre><code>val anon1 = plus2(_,_) val anon2 = plus2 _ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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