Skip to content

Rank 1 type signature still requires RankNTypes

When trying to figure out which type variable names are *actually* bound in ScopedTypeVariables, I tried floating foralls into the covariant argument of the function type. Essentially, I ran into the problem that programs like the following are rejected:

{-# LANGUAGE ExplicitForAll #-}
tuple :: forall a. a -> (forall b. b -> (a, b))
tuple = (,)

The message is as follows:

Main.hs:2:10:
    Illegal polymorphic or qualified type: forall b. b -> (a, b)
    Perhaps you intended to use -XRankNTypes or -XRank2Types
    In the type signature for `tuple':
      tuple :: forall a. a -> (forall b. b -> (a, b))

As far as I know, the rank of a type is defined by how deep quantifiers are nested in contravariant parts of that type. Or something like that. Also, as far as I know, forall a. a -> (forall b. b -> (a, b)) is equivalent to forall a b. a -> b -> (a, b), and more importantly, both are rank-1 polymorphic. There should be no need to use extensions that allow higher-ranked polymorphism.

Trac metadata
Trac field Value
Version 7.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information