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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With