Why annotating a lambda type doesn't require -XScopedTypeVariables?

haskell

Solution

More generally than that: standard Haskell doesn't allow signatures in patterns, but does allow any expression to be given a signature. The following are all valid:

main :: IO ()
main = do
   x <- readLn
   print $ 5 + x

main' = (\y -> do {
   x <- readLn;
   print $ y + x } ) :: Int -> IO ()

main'' y = do
   x <- readLn :: IO Int
   print $ y + x :: IO ()

but none of these are

main''' = do
   (x :: Int) <- readLn
   print $ 5 + x

main''' = (\(y :: Int) -> do {
   x <- readLn;
   print $ y + x } ) :: Int -> IO ()

main'''' (y :: Int) = do
   x <- readLn :: IO Int
   print $ y + x :: IO ()

Apparently, it was just not envisioned that signatures in patterns might be useful. But they sure are, so `ScopedTypeVariables` introduced that possibility.

Problem

This requires `-XScopedTypeVariables` ``` handle(\(_::SomeException) -> return Nothing) ``` but this doesn't ``` handle((\_ -> return Nothing)::SomeException -> IO (Maybe Integer)) ``` If `::` is allowed to annotated types inside function body, why does it require a pragma to annotate a local variable?

Original source