ScopedTypeVariable and RankNTypes don't scope throughout function body
I'm writing a DSL that uses TypeApplications, and I noticed the following weird behavior with ScopedTypeVariables and AllowAmbiguousTypes.
You can define a function that takes the TypeApplication after a parameter:
lol :: String -> forall a. IO ()
lol str = putStrLn str
main = lol "hello" @Int
This works! Unfortunately, it is impossible to *refer* to that a type variable in the body of the function. It is as though ScopedTypeVariables were not turned on.
A reproduction (tested on 8.2.2 and 8.4.1):
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Typeable
import Data.Proxy
no :: String -> forall x. Typeable x => IO ()
no _ = print (typeRep (Proxy :: Proxy x))
yes :: forall x. Typeable x => String -> IO ()
yes _ = print (typeRep (Proxy :: Proxy x))
no fails to compile, saying that x type variable is not in scope. yes works just fine.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |