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

This requires -XScopedTypeVariables

 handle(\(_::SomeException) -> return Nothing) 

But it is not

 handle((\_ -> return Nothing)::SomeException -> IO (Maybe Integer)) 

If :: allowed for annotated types inside a function body, why do we need a pragma to annotate a local variable?

+6
source share
1 answer

More generally: standard Haskell does not allow signatures in templates, but allows any expression to receive a signature. The following conditions are 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 not one of them is

 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 is simply not foreseen that the signatures in the templates may be useful. But they are sure, therefore ScopedTypeVariables presented this opportunity.

+10
source

All Articles