Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Indeed, it's possible to parse simple grammar for (even nested) patterns without parens at all. Suppose such one:</p> <pre><code>&lt;PAT&gt; ::= &lt;WILDCARD&gt; | &lt;VAR&gt; | &lt;CON0&gt; | &lt;CON1&gt; &lt;PAT&gt; | &lt;CON2&gt; &lt;PAT&gt; &lt;PAT&gt; ... &lt;VAR&gt; ::= &lt;LNAME&gt; &lt;CON*&gt; ::= &lt;UNAME&gt; &lt;WILD&gt; ::= "_" </code></pre> <p>where LNAME is names that starts with lowercase letter and UNAME starts with uppercase letter. While parsing we should look up constructor name so we can find out its arity. Then we can parse constructor fields using arity information. But this lookup might significant complicate and slow down parsing itself. Haskell has much more complex patterns(view patterns, "as" patterns, records, infix constructors with arbitrary fixity, e.t.c.) and omitting parens can lead to ambiguity.</p> <p>Though there is another reason not to do that. Consider the following code:</p> <pre><code>data Bar = Bar Int data Foo = Foo Int libFunction Foo a Bar b = a + b someUse bar foo = libFunction foo bar </code></pre> <p>Next imagine we change datatypes a bit:</p> <pre><code>data Bar = Bar data Foo = Foo Int Bar Int </code></pre> <p>Modified code might still typecheck, but the function will do not that we expect. Not a real world example but nevertheless. And since Haskell have type classes it can be pretty hard to find out where we get something wrong.</p> <p>In other words: we can loose quality of error messages and parens defends us from unexpected behaviour after changes.</p>
    singulars
    1. This table or related slice is empty.
    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