Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just to make things more explicit, this data type:</p> <pre><code>data List a = Cons a (List a) | Nil </code></pre> <p>...has the same structure as the built-in list type, but without the (nicer, but potentially confusing) special syntax. Here's what some correspondences look like:</p> <ul> <li><code>List</code> = <code>[]</code>, type constructors with kind <code>* -&gt; *</code></li> <li><code>List a</code> = <code>[a]</code>, types with kind <code>*</code></li> <li><code>Nil</code> = <code>[]</code>, values with polymorphic types <code>List a</code> and <code>[a]</code> respectively</li> <li><code>Cons</code> = <code>:</code>, data constructors with types <code>a -&gt; List a -&gt; List a</code> and <code>a -&gt; [a] -&gt; [a]</code> respectively</li> <li><code>Cons 5 Nil</code> = <code>[5]</code> or <code>5:[]</code>, single element lists</li> <li><code>f Nil = ...</code> = <code>f [] = ...</code>, pattern matching empty lists</li> <li><code>f (Cons x Nil) = ...</code> = f [x] = ...`, pattern matching single-element lists</li> <li><code>f (Cons x xs) = ...</code> = <code>f (x:xs) = ...</code>, pattern matching non-empty lists</li> </ul> <p>In fact, if you ask ghci about <code>[]</code>, it tells you pretty much the same definition:</p> <pre><code>&gt; :i [] data [] a = [] | a : [a] -- Defined in GHC.Types </code></pre> <p>But you can't write such a definition yourself because the list syntax and its "outfix" type constructor is a special case, defined in the language spec.</p>
    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