Proposed refactoring: Make lambda and \case use the same constructor.
The \case and \cases AST nodes are defined by a single constructor, but lambda isn't:
| HsLam (XLam p) (MatchGroup p (LHsExpr p))
| HsLamCase (XLamCase p) LamCaseVariant (MatchGroup p (LHsExpr p))
XLam actually is NoExtField, so we can merge these data constructors without any additional problems. The main change:
data LamCaseVariant
= LamCase -- ^ `\case`
| LamCases -- ^ `\cases`
+ | Lambda -- ^ `\`
data HsExpr p =
...
- | HsLam (XLam p) (MatchGroup p (LHsExpr p))
...
And the same for HsCmdLam
Edited by Andrei Borzenkov