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

#12716: Suggest ScopedTypeVariables when type variable not in scope -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I recently wrote this: {{{ {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE TypeApplications #-} module B where f :: forall a. a -> a f x = id @a x }}} And was hornswoggled for the better part of five minutes for why "a" wasn't in scope. Answer: you need `ScopedTypeVariables`. A suggestion would be nice. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12716 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12716: Suggest ScopedTypeVariables when type variable not in scope -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Resolution: | 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 thomie): Duplicate of #9244 (and #1316, #3691, #11438, #10581, #11539, ...). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12716#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => duplicate -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12716#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 ezyang): I saw that bug, but it looks completely different (a request for name shadowing warnings at the type variable level), but OK ;) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12716#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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
participants (1)
-
GHC