GHC: Ticket #6032: HEAD (7.5.20120421) requires RankNTypes for a rank-2 type
http://ghc.haskell.org/trac/ghc/ticket/6032
<p>
While building syb with HEAD, Ian reported that he needed to use RankNTypes instead of Rank2Types. I minimized the problem to:
</p>
<pre class="wiki">{-# LANGUAGE Rank2Types #-}
module Rank2 where
f :: (forall a. a -> (forall b. b)) -> c
f = undefined
g :: (forall a b. a -> b) -> c
g = undefined
</pre><p>
7.4 accepts both <tt>f</tt> and <tt>g</tt>. HEAD complains on the signature of <tt>f</tt>:
</p>
<pre class="wiki"> Illegal polymorphic or qualified type: forall b. b
Perhaps you intended to use -XRankNTypes or -XRank2Types
In the type signature for `f':
f :: (forall a. a -> (forall b. b)) -> c
</pre><p>
It doesn't complain about <tt>g</tt>, but I think the signatures are equivalent. Ian further reports that the change in behavior seems to have occurred after 7.5.20120401.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/6032
Trac 1.0.9simonpjMon, 23 Apr 2012 13:28:55 GMTdifficulty set
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:1
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:1
<ul>
<li><strong>difficulty</strong>
set to <em>Unknown</em>
</li>
</ul>
<p>
The difficulty is this
</p>
<ul><li>The argument of a rank-2 arrow type should have rank 1
</li><li>A vanilla H98 type sig has rank 1
</li><li>But technically <tt>(Int -> forall a. a->a)</tt> is rank 1, although it is not H98.
</li></ul><p>
GHC currently has the (somewhat ad-hoc) restriction that a rank-1 type must have all its foralls at the front, which is why this program is rejected. And yes that's a change in behaviour. (A different bug report said that <tt>(Int -> forall a. a->a)</tt> was accepted despite no higher-rank flags being on.
</p>
<p>
Perhaps it'd be better to always accept foralls to the right of an arrow. After all, you need at least <tt>-XForAllTypes</tt> to be able to write them.
</p>
TicketdreixelTue, 24 Apr 2012 12:51:06 GMT
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:2
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:2
<p>
I don't feel strongly about it either way. We can change <tt>syb</tt> to use the rank-n flag. Is there even a good reason to distinguish rank-2 from rank-n?
</p>
TicketsimonpjTue, 24 Apr 2012 13:03:08 GMT
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:3
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:3
<p>
I don't think so. I'd be happy to see <tt>-XRank2Types</tt> deprecated. One less thing to deal with.
</p>
TicketiglooSun, 07 Oct 2012 16:42:23 GMTowner, milestone set
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:4
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:4
<ul>
<li><strong>owner</strong>
set to <em>simonpj</em>
</li>
<li><strong>milestone</strong>
set to <em>7.8.1</em>
</li>
</ul>
TickettibbeFri, 19 Oct 2012 16:34:00 GMTcc set
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:5
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:5
<ul>
<li><strong>cc</strong>
<em>johan.tibell@…</em> added
</li>
</ul>
<p>
Deprecating Rank2Types would require fixing 775 modules on Hackage. That's a lot of busy work. Could we have Rank2Types just be an alias for RankNTypes?
</p>
TicketsimonpjFri, 19 Oct 2012 16:49:23 GMT
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:6
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:6
<p>
Well it'd be odd to have "2" as a <em>permanent</em> alias for "arbitrary" wouldn't it? Isn't this precisely what deprecation is for: everything works but you get a nudge saying "please change when it's convenient". In fact it *is* an alias for <tt>RankNTypes</tt> plus a deprecation message.
</p>
<p>
We can keep supporting <tt>Rank2Types</tt> (as an alias for <tt>RankNTypes</tt>), with deprecation, for multiple releases.
</p>
<p>
Or what?
</p>
<p>
Simon
</p>
TicketillissiusFri, 19 Oct 2012 17:43:25 GMT
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:7
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:7
<p>
Might the reason for the separation have been that type inference is in theory decidable for rank-2 types, but not higher? I'm not a type theorist but I found this for example: <a class="ext-link" href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.144.1202"><span class="icon"></span>http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.144.1202</a>
(WRT the deprecation/aliasing proposal itself I don't have an opinion)
</p>
Ticketsimonpj@…Fri, 26 Oct 2012 10:08:43 GMT
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:8
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:8
<p>
commit <a class="changeset" href="http://ghc.haskell.org/trac/ghc/changeset/984676d51291ea900cec289599e647de38645405/ghc" title="Deprecate Rank2Types and PolymorphicComponents, in favour of ...">984676d51291ea900cec289599e647de38645405</a>
</p>
<pre class="wiki">Author: Simon Peyton Jones <simonpj@microsoft.com>
Date: Fri Oct 19 00:54:59 2012 +0100
Deprecate Rank2Types and PolymorphicComponents, in favour of RankNTypes
We agreed that it's not worth the bother of trying to maintain all
these distinct flags; RankNTypes will do the job fine. Trac #6032.
compiler/main/DynFlags.hs | 11 ++++-------
compiler/prelude/PrelRules.lhs | 2 +-
compiler/simplCore/OccurAnal.lhs | 2 +-
compiler/typecheck/TcMType.lhs | 13 +++----------
4 files changed, 9 insertions(+), 19 deletions(-)
</pre>
TicketsimonpjFri, 26 Oct 2012 15:24:02 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:9
http://ghc.haskell.org/trac/ghc/ticket/6032#comment:9
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
Ticket