template-haskell's RecordWildCards support
Summary
RecordWildCards syntax Con {..}
doesn't appear to be represented in template-haskell.
Suppose we have a data type:
data G = H { field0 :: Int, field1 :: String }
deriving stock Show
Using [e|H {..}|]
yields RecConE Main.H []
.
But this is indistinguishable from [e|H {}|]
.
However, using H {}
in place of H {..}
won't compile if H
has fields.
Expected behavior
Have RecConE
support wildcards.
(Solutionising)
Perhaps something like:
data RecWild = NoRecWildCard | RecWildCard
data Exp ...
| RecConE Name [FieldExp] RecWild
data Pat ...
| RecP Name [FieldPat] RecWild
Supporting both H {..}
and H {field1=42, ..}
.
Maybe .Lib
could keep its existing recConE
& recP
but add recConWildE
& recWildP
? (if that's desirable)
recConE :: Quote m => Name -> [m (Name, Exp)] -> m Exp
recConE c fs = do { flds <- sequenceA fs; pure (RecConE c flds NoRecWildCard) }
recConWildE :: Quote m => Name -> [m (Name, Exp)] -> m Exp
recConWildE c fs = do { flds <- sequenceA fs; pure (RecConE c flds RecWildCard) }
Environment
- GHC version used: 9.8.2 and below.