Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>()</code> in a function type is not a type at all, nor is it a value. <code>() =&gt;</code> is simply syntax to indicate a function that takes zero arguments. See the BNF notation in section 3.2.9 of <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf" rel="noreferrer">the Scala specification.</a></p> <p>When you see <code>(Type1, Type2, Type3) =&gt; Type4</code>, the <code>()</code> surrounds all of the argument types that the function takes. <code>(Type1, Type2, Type3)</code> is not a tuple type here -- the parentheses are just syntax. So when you see <code>() =&gt; Type4</code>, you have an argument list that takes zero parameters. Single argument functions are special, in that you can omit the parentheses. </p> <p>Functions with no arguments, specified without the <code>()</code>, simply <code>=&gt; Type4</code> are by-name parameters (which look like values, but are implemented as functions that get called implicitly when you try to evaluate their value.) They're defined in section 4.6.1 of the spec.</p> <p>Parentheses can mean a bunch of other things in other contexts.</p> <ul> <li>Parentheses in a function type declaration anywhere other than right before the <code>=&gt;</code> indicate a tuple type, and these can't be empty. (Section 3.2.5)</li> <li><p>Empty parentheses <code>()</code> are the return value of functions whose return type is <code>Unit</code>. (Section 12.2.3) This actually becomes a real value in certain contexts, for example <code>println(println("foo"))</code> will print</p> <pre><code>foo &lt;--- the argument to the inner println () &lt;--- the argument to the outer println </code></pre></li> <li><p>Parentheses are also syntax for function arguments when you make a function call, something that you're probably already aware of. These can be empty. They're defined in section 6.6 of the spec.</p></li> <li>Parentheses are also syntax for function arguments when you define a method using <code>def</code>. These are described in section 4.6 of the spec.</li> <li>Parentheses are also the syntax for creating tuple values (Section 6.9). If they're not empty, you get a <code>TupleN</code> where <code>N</code> is the number of values inside of the parentheses. If they are empty, the type of this expression is <code>Unit</code>. (Sections 6.9, 12.2.3)</li> </ul>
    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. 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.
    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