Skip to content

Support invisible type patterns in Template Haskell quotes (e.g., [t| @a |])

I am using GHC 9.10.1-alpha1, which introduces @-binders in more places in pattern contexts (!11109 (closed)). Based on one of the test cases added in that MR, I discovered that TypeAbstractions could be combined with LambdaCase, e.g.,

{-# LANGUAGE GHC2024 #-}
{-# LANGUAGE TypeAbstractions #-}
module Foo where

import Data.Kind

f :: (forall (a :: Type). ()) -> ()
f k = k @Bool

g :: ()
g = f (\cases
         @a -> ())

Great. What is surprising, however, is that if I change \cases to be \case:

g :: ()
g = f (\case
         @a -> ())

Then GHC fails to parse it:

$ ghc-9.10 Foo.hs
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )

Foo.hs:11:8: error: [GHC-06074]
    Unexpected \case expression in function application:
        \case
    Suggested fixes:
      • Use parentheses.
      • Perhaps you intended to use BlockArguments
   |
11 | g = f (\case
   |        ^

Foo.hs:11:8: error: [GHC-66228]
    View pattern in expression context: \case @a -> ()
   |
11 | g = f (\case
   |        ^^^^^...

This feels inconsistent, as I would expect that if \cases works, then \case should also work. Is this intended?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information