-data HsConDetails id arg
- = PrefixCon [arg] -- C p1 p2 p3
- | RecCon [(Located id, arg)] -- C { x = p1, y = p2 }
- | InfixCon arg arg -- p1 `C` p2
-
-hsConArgs :: HsConDetails id arg -> [arg]
-hsConArgs (PrefixCon ps) = ps
-hsConArgs (RecCon fs) = map snd fs
-hsConArgs (InfixCon p1 p2) = [p1,p2]
+data HsConDetails arg rec
+ = PrefixCon [arg] -- C p1 p2 p3
+ | RecCon rec -- C { x = p1, y = p2 }
+ | InfixCon arg arg -- p1 `C` p2
+
+type HsConPatDetails id = HsConDetails (LPat id) (HsRecFields id (LPat id))
+
+hsConPatArgs :: HsConPatDetails id -> [LPat id]
+hsConPatArgs (PrefixCon ps) = ps
+hsConPatArgs (RecCon fs) = map hsRecFieldArg (rec_flds fs)
+hsConPatArgs (InfixCon p1 p2) = [p1,p2]
+\end{code}
+
+However HsRecFields is used only for patterns and expressions
+(not data type declarations)
+
+\begin{code}
+data HsRecFields id arg -- A bunch of record fields
+ -- { x = 3, y = True }
+ -- Used for both expressiona and patterns
+ = HsRecFields { rec_flds :: [HsRecField id arg],
+ rec_dotdot :: Maybe Int }
+ -- Nothing => the normal case
+ -- Just n => the group uses ".." notation,
+ -- and the first n elts of rec_flds
+ -- were the user-written ones
+ -- (In the latter case, the remaining elts of
+ -- rec_flds are the non-user-written ones)
+
+data HsRecField id arg = HsRecField {
+ hsRecFieldId :: Located id,
+ hsRecFieldArg :: arg,
+ hsRecPun :: Bool -- Note [Punning]
+ }
+
+-- Note [Punning]
+-- ~~~~~~~~~~~~~~
+-- If you write T { x, y = v+1 }, the HsRecFields will be
+-- HsRecField x x True ...
+-- HsRecField y (v+1) False ...
+-- That is, for "punned" field x is immediately expanded to x=x
+-- but with a punning flag so we can detect it later
+-- (e.g. when pretty printing)
+
+hsRecFields :: HsRecFields id arg -> [id]
+hsRecFields rbinds = map (unLoc . hsRecFieldId) (rec_flds rbinds)