[GHC] #12716: Suggest ScopedTypeVariables when type variable not in scope

GHC ghc-devs at haskell.org
Wed Oct 19 11:52:03 UTC 2016


#12716: Suggest ScopedTypeVariables when type variable not in scope
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                Owner:
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |
      Resolution:  duplicate         |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 I would love someone to work on this a bit.

 In Edward's example above, it would be relatively easy to put 'a' in the
 environment with a flag to say "Not really in scope unless you use
 `ScopedTypeVariables`.

 But there is more thinking to do.  What if he'd written
 {{{
 f :: forall a. a -> a
 f x = let g :: a -> a
           g _ = x
       in g x
 }}}
 Here the programmer probably intended the inner `a -> a` to be scoped by
 the `forall`; but as it stands, without `ScopedTypeVariables` it means
 {{{
   g :: forall a. a->a
 }}}
 which will then be rejected by the type checker.

 I suggest that

 * `ExplicitForAll` should imply `ScopedTypeVariables`.  (The reverse is
 already true!)

 * 'RankNTypes` should imply `ScopedTypeVariables`.  (`RankNTypes` already
 implies `ExplicitForAll`, so the earlier bullet would imply this one.)

 You could always say `ExplicitForAll, NoScopedTypeVariables` if you really
 wanted.

 That still leaves #9244 and friends wanting a better error
 message/suggestion.
 Simon

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12716#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list