Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>()</code> type can be thought of as a zero-element tuple. It's a type that can only have one value, and thus it's used where you need to have a type, but you don't actually need to convey any information. Here's a couple of uses for this.</p> <p>Monadic things like <code>IO</code> and <code>State</code> have a return value, as well as performing side-effects. Sometimes the only point of the operation is to perform a side-effect, like writing to the screen or storing some state. For writing to the screen, <code>putStrLn</code> must have type <code>String -&gt; IO ?</code> -- <code>IO</code> always has to have some return type, but here there's nothing useful to return. So what type should we return? We could say Int, and always return 0, but that's misleading. So we return <code>()</code>, the type that has only one value (and thus no useful information), to indicate that there's nothing useful coming back.</p> <p>It's sometimes useful to have a type which can have no useful values. Consider if you'd implemented a type <code>Map k v</code> which maps keys of type <code>k</code> to values of type <code>v</code>. Then you want to implement a <code>Set</code>, which is really similar to a map except that you don't need the value part, just the keys. In a language like Java you might use booleans as the dummy value type, but really you just want a type that has no useful values. So you could say <code>type Set k = Map k ()</code></p> <p>It should be noted that <code>()</code> is not particularly magic. If you want you can store it in a variable and do a pattern match on it (although there's not much point):</p> <pre><code>main = do x &lt;- putStrLn "Hello" case x of () -&gt; putStrLn "The only value..." </code></pre>
    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.
    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