Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, it's not part of the Haskell 2010 standard, so it's not on by default, and is offered as a language extension instead. As for why it's not in the standard, rank-n types are quite a bit harder to implement than the plain rank-1 types standard Haskell has; they're also not needed all that frequently, so the Committee likely decided not to bother with them for reasons of language and implementation simplicity.</p> <p>Of course, that doesn't mean rank-n types aren't useful; they are, very much so, and without them we wouldn't have valuable tools like the <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad-ST.html" rel="nofollow noreferrer"><code>ST</code> monad</a> (which offers efficient, local mutable state — like <code>IO</code> where all you can do is use <code>IORef</code>s). But they do add quite a bit of complexity to the language, and can cause strange behaviour when applying seemingly benign code transformations. For instance, some rank-n type checkers will allow <code>runST (do { ... })</code> but reject <code>runST $ do { ... }</code>, even though the two expressions are always equivalent without rank-n types. See <a href="https://stackoverflow.com/questions/8343239/type-error-with-rank-2-types-and-function-composition">this SO question</a> for an example of the unexpected (and sometimes annoying) behaviour it can cause.</p> <p>If, like sepp2k asks, you're instead asking why <code>forall</code> has to be explicitly added to type signatures to get the increased generality, the problem is that <code>(forall x. x -&gt; f x) -&gt; (a, b) -&gt; (f a, f b)</code> is actually a more restrictive type than <code>(x -&gt; f x) -&gt; (a, b) -&gt; (f a, f b)</code>. With the latter, you can pass in any function of the form <code>x -&gt; f x</code> (for any <code>f</code> and <code>x</code>), but with the former, the function you pass in must work for <em>all</em> <code>x</code>. So, for instance, a function of type <code>String -&gt; IO String</code> would be a permissible argument to the second function, but not the first; it'd have to have the type <code>a -&gt; IO a</code> instead. It would be pretty confusing if the latter was automatically transformed into the former! They're two very different types.</p> <p>It might make more sense with the implicit <code>forall</code>s made explicit:</p> <pre><code>forall f x a b. (x -&gt; f x) -&gt; (a, b) -&gt; (f a, f b) forall f a b. (forall x. x -&gt; f x) -&gt; (a, b) -&gt; (f a, f b) </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. 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