goldfirere / th-desugar

Desugars Template Haskell abstract syntax to a simpler format without changing semantics
BSD 3-Clause "New" or "Revised" License
19 stars 13 forks source link

Add support for invisible type patterns in lambda and `\cases` expressions #205

Closed RyanGlScott closed 2 months ago

RyanGlScott commented 5 months ago

GHC 9.10 introduces the ability to use invisible type patterns. As such, examples like this can now be written:

id :: a -> a
id @t x = x :: t

As a preliminary, we'd need a th-desugar counterpart to InvisP, which was introduced in template-haskell-2.22.0.0 (shipped with GHC 9.10.1):

data Pat
  = ...
  | InvisP Type                     -- ^ @{ @p }@

Note that @-binders can also be used in lambda expressions and \cases expressions, which means that it is possible to write things like the following:

aux :: (forall a. a -> a) -> ()
aux z = z ()

f :: ()
f = aux (\ @a (x :: a) -> x :: a)

g :: forall a -> Maybe a -> a -> a
g = aux (\cases @a (x :: a) -> x :: a)

This means that @-binders are susceptible to challenges (1) and (2) from #204. (Thankfully, it's not susceptible to challenge (3), since invisible type patterns are always clearly marked with @.)

RyanGlScott commented 4 months ago

211 implemented partial support for invisible type patterns. You can now desugar invisible type patterns in function clauses, but not in lambda expressions or \cases expressions. I've retitled this issue to track the remaining task of supporting invisible type patterns in lambda and \cases expressions.